Accessing undeclared field does not raise a type error

Open
#51 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
compilers

Research direction

Start with the lookup_self_field_neg.py reproducer and trace the Static Python type-checking path for c.x when C declares no fields. Confirm the current behavior, then make the checker report that C has no attribute x and verify the reproducer produces a compile-time error.

Written by the indexing model from the issue text.

Description

sp-correctness staticpython

6862bbd
2021-10-13

What program did you run?
# lookup_self_field_neg.py
# This should fail.

class C:
    pass

def f(c: C):
    # reveal_type(c.x) # dynamic
    return c.x
What happened?

The program passes type checks.

What should have happened?

We expected a compile-time error complaining that "C has no attribute x". (This is what mypy does.)

Is this another case where Static Python falls back to dynamic (similar to #50)?

Dominant language
Python
Stars
3.8k
Forks
139
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebookincubator/MetaPython

All issues in facebookincubator/MetaPython

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.