Skip to content

Commit 456cc77

Browse files
committed
infer-function-types: fix infer from defaults with inner functions
1 parent 48f2fec commit 456cc77

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixes
1010
- Handle positional only `/` parameters in overload implementation inference
1111
- Render inferred literal without `?`
12+
- Fix infer from defaults for inner functions
1213

1314
## [1.5.0]
1415
### Added

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3134,7 +3134,7 @@ def analyze_simple_literal_type(
31343134
) -> Type | None:
31353135
"""Return builtins.int if rvalue is an int literal, etc.
31363136
If this is a 'Final' context, we return "Literal[...]" instead."""
3137-
if self.options.semantic_analysis_only or self.function_stack:
3137+
if self.options.semantic_analysis_only or self.function_stack and not do_bools:
31383138
# Skip this if we're only doing the semantic analysis pass.
31393139
# This is mostly to avoid breaking unit tests.
31403140
# Also skip inside a function; this is to avoid confusing

test-data/unit/check-based-infer-function-types.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,9 @@ def deco(func: T) -> T: ...
468468
def b(b=True) -> None: ...
469469

470470
reveal_type(b) # N: Revealed type is "def (b: bool =) -> None"
471+
472+
473+
[case testInferFromDefaultNested]
474+
def f1():
475+
def f2(a=True): ...
476+
reveal_type(f2) # N: Revealed type is "def (a: bool =) -> None"

0 commit comments

Comments
 (0)