Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit13f35ad

Browse files
authored
Fix crash related to propagating type narrowing to nested functions (#15181)
See#15133 (comment)for context.
1 parentd17b3ed commit13f35ad

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

‎mypy/checker.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ def check_func_def(
12221222
ifnew_frameisNone:
12231223
new_frame=self.binder.push_frame()
12241224
new_frame.types[key]=narrowed_type
1225+
self.binder.declarations[key]=old_binder.declarations[key]
12251226
withself.scope.push_function(defn):
12261227
# We suppress reachability warnings when we use TypeVars with value
12271228
# restrictions: we only want to report a warning if a certain statement is

‎test-data/unit/check-optional.test‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,3 +1329,17 @@ def narrow_with_multi_assign_3(x: Optional[str]) -> None:
13291329
y, x = None, None
13301330

13311331
[builtins fixtures/isinstance.pyi]
1332+
1333+
[case testNestedFunctionSpecialCase]
1334+
class C:
1335+
def __enter__(self, *args): ...
1336+
def __exit__(self, *args) -> bool: ...
1337+
1338+
def f(x: object) -> None:
1339+
if x is not None:
1340+
pass
1341+
1342+
def nested() -> None:
1343+
with C():
1344+
pass
1345+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp