Skip to content

Switch error code used to report vars defined in different branch - #14176

Merged
ilinum merged 2 commits into
python:masterfrom
ilinum:partial/defined-diff-branch-no-use-before-def
Nov 25, 2022
Merged

ilinum merged 2 commits into
python:masterfrom
ilinum:partial/defined-diff-branch-no-use-before-def

Conversation

@ilinum

@ilinum ilinum commented Nov 23, 2022

Copy link
Copy Markdown
Collaborator

We previously used use-before-def code here but this commit switched it to use partially-defined. This particular check generates a lot of false positives, in particular around loops of the form:

for i in range(2)
  if i == 0:
    x = 1
  else:
    y = x

While in an ideal world mypy has no false positives, it's not feasible for us to handle this correctly in the short-term. Moving this to partially-defined error code makes the use-before-def have a much lower false positive rate, which is a plus. Unfortunately, partially-defined will always have a higher false positive rate. This means that if we enable it by default, lots of people will disable this check. We want to avoid the same thing happening to use-before-def check.

See this PR for further discussion.

Comment thread mypy/partially_defined.py Resolved
@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@ilinum
ilinum merged commit db0beb1 into python:master Nov 25, 2022
@ilinum
ilinum deleted the partial/defined-diff-branch-no-use-before-def branch November 25, 2022 20:03
JukkaL pushed a commit that referenced this pull request Dec 19, 2022
A similar case was addressed in #14176 but I missed the part where it
doesn't need to be defined in a different branch. This makes the fix
more complete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants