KEMBAR78
Allow redefinitions in except/else/finally by sterliakov · Pull Request #18515 · python/mypy · GitHub
Skip to content

Conversation

sterliakov
Copy link
Collaborator

Fixes #18514.

Only try clause should be treated as fallible, this should not prevent --allow-redefinition from working in other try clauses (except, else, finally).

# E: Incompatible types in assignment (expression has type "int", variable has type "TypeVar")
reveal_type(x) # N: Revealed type is "typing.TypeVar"
y = 1
# NOTE: '"int" not callable' is due to test stubs
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This note no longer applies, necessary stubs were connected in #17384.

@github-actions

This comment has been minimized.

@sterliakov sterliakov marked this pull request as ready for review January 23, 2025 15:35
@github-actions

This comment has been minimized.

a = ""
a = fn_str(a) # E: Incompatible types in assignment (expression has type "int", variable has type "str")
fn_int(a) # E: Argument 1 to "fn_int" has incompatible type "str"; expected "int"
except:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, also test except *

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@sobolevn sobolevn merged commit 0451880 into python:master Jan 26, 2025
18 checks passed
x612skm pushed a commit to x612skm/mypy-dev that referenced this pull request Feb 24, 2025
Fixes python#18514.

Only `try` clause should be treated as fallible, this should not prevent
`--allow-redefinition` from working in other try clauses (except, else,
finally).
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.

Redefinition doesn't work in else branch of try

3 participants