Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

ilinum
Copy link
Collaborator

@ilinum ilinum commented Nov 23, 2022

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.

@github-actions

This comment has been minimized.

@github-actions
Copy link
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