python / python/mypy

New semantic analyzer: better error messages for cyclic cross-module definitions

Open
#6,551 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority-1-normal semantic-analyzer topic-error-reporting topic-usability
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

This is a follow-up for https://github.com/python/mypy/pull/6527

The new analyzer gives to verbose (and a bit confusing) error in this case:

[case testNewAnalyzerCyclicDefinitionCrossModule]
import b
[file a.py]
import b
x = b.x  # E: Cannot determine type of 'x'
[file b.py]
import a
x = a.x  # E: Cannot resolve attribute "x", possible cyclic definition \
         # E: Module has no attribute "x"

We can probably skip the second part by injecting a dummy Var with Any type in the a module namespace.

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 with the testNewAnalyzerCyclicDefinitionCrossModule case shown in the issue and compare its expected diagnostics with the new analyzer behavior. Read the follow-up context in pull request 6527 and trace how cyclic cross-module attributes are resolved. Done means the redundant diagnostic is removed while the useful cyclic-definition error remains covered by the test.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.