python / python/mypy

Use analyzed type when resolving attributes via __getattr__

Open
#5,345 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-1-normal topic-import-cycles
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Currently, there are several places in code where mypy uses .ret_type of __getattr__ function during semantic analysis to create a dummy Var if the attribute is missing. This can result in type being in unanalyzed state (UnboundType) in certain conditions (for example an import cycle) which then leaks to later stages where it can cause weird errors, and potentially even crashes.

This is especially important now, since __getattr__ can be used also outside stubs.

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.

Research direction

Start by locating the semantic-analysis code paths that use getattr's .ret_type to create a dummy Var when an attribute is missing. Trace how an UnboundType can pass through import cycles, and consider the issue complete when the analyzed type is used and unanalyzed types no longer leak into later stages or cause crashes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.