Skip to content

Commit

Permalink
infer-function-types: fix infer from defaults with inner functions
Browse files Browse the repository at this point in the history
  • Loading branch information
KotlinIsland committed Aug 14, 2022
1 parent 0636c9d commit a1480df
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Fixes
- Handle positional only `/` parameters in overload implementation inference
- Render inferred literal without `?`
- Fix infer from defaults for inner functions

## [1.5.0]
### Added
Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3040,7 +3040,7 @@ def analyze_simple_literal_type(
"""Return builtins.int if rvalue is an int literal, etc.
If this is a 'Final' context, we return "Literal[...]" instead."""
if self.options.semantic_analysis_only or self.function_stack:
if self.options.semantic_analysis_only or self.function_stack and not do_bools:
# Skip this if we're only doing the semantic analysis pass.
# This is mostly to avoid breaking unit tests.
# Also skip inside a function; this is to avoid confusing
Expand Down
6 changes: 6 additions & 0 deletions test-data/unit/check-based-infer-function-types.test
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,9 @@ def deco(func: T) -> T: ...
def b(b=True) -> None: ...

reveal_type(b) # N: Revealed type is "def (b: bool =) -> None"


[case testInferFromDefaultNested]
def f1():
def f2(a=True): ...
reveal_type(f2) # N: Revealed type is "def (a: bool =) -> None"

0 comments on commit a1480df

Please sign in to comment.