Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ def check_func_def(
if new_frame is None:
new_frame = self.binder.push_frame()
new_frame.types[key] = narrowed_type
self.binder.declarations[key] = old_binder.declarations[key]
with self.scope.push_function(defn):
# We suppress reachability warnings when we use TypeVars with value
# restrictions: we only want to report a warning if a certain statement is
Expand Down
14 changes: 14 additions & 0 deletions test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -1329,3 +1329,17 @@ def narrow_with_multi_assign_3(x: Optional[str]) -> None:
y, x = None, None

[builtins fixtures/isinstance.pyi]

[case testNestedFunctionSpecialCase]
class C:
def __enter__(self, *args): ...
def __exit__(self, *args) -> bool: ...

def f(x: object) -> None:
if x is not None:
pass

def nested() -> None:
with C():
pass
[builtins fixtures/tuple.pyi]