Skip to content
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

Allow redefinitions in except/else/finally #18515

Merged

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).

@@ -274,7 +320,6 @@ def f() -> None:
# 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.

This comment has been minimized.

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

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 *

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
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