python / python/mypy

Consider deferring module top level in type checker

Open
#6,356 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature priority-0-high topic-import-cycles
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

We currently never defer module top levels in type checker. This can cause some Cannot determine type of x errors in import cycles. They are real in some sense, because such code would almost certainly fail at runtime. However, this might sometimes be useful in stubs (as practice shows, this is however not important and shows up only in highly entangled import cycles, such as e.g. builtins SCC).

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

No files, tests, or entry points are named. Start by tracing module top-level handling in the type checker and reproduce the reported Cannot determine type of x errors in an import cycle, including the builtins SCC case; done requires a decided deferral policy and tests showing the intended stub behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.