Skip to content

Commit a1480df

Browse files
committed
infer-function-types: fix infer from defaults with inner functions
1 parent 0636c9d commit a1480df

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3040,7 +3040,7 @@ def analyze_simple_literal_type(
30403040
"""Return builtins.int if rvalue is an int literal, etc.
30413041
30423042
If this is a 'Final' context, we return "Literal[...]" instead."""
3043-
if self.options.semantic_analysis_only or self.function_stack:
3043+
if self.options.semantic_analysis_only or self.function_stack and not do_bools:
30443044
# Skip this if we're only doing the semantic analysis pass.
30453045
# This is mostly to avoid breaking unit tests.
30463046
# Also skip inside a function; this is to avoid confusing

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

+6
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)