You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A method returning only boolean values is inferred as returning Any
To Reproduce
See the following minimal example:
defis_valid_hwnd(hwnd: int):
ifnothwnd:
returnFalsereturnTruereveal_type(is_valid_hwnd(0)) # note: Revealed type is "Any"
The real-world example is as such:
defis_valid_hwnd(hwnd: int):
"""Validate the hwnd points to a valid window and not the desktop or whatever window obtained with `""`."""ifnothwnd:
returnFalseifsys.platform=="win32":
returnbool(win32gui.IsWindow(hwnd) andwin32gui.GetWindowText(hwnd))
returnTrue
Which is much more readable than a boolean expression. But even that surprisingly is inferred as Any:
The return type should be inferred as bool. Even Literal[True, False] or Literal[True, False] | bool would be fine.
Actual Behavior
Return type is inferred as Any
Your Environment
Mypy version used: mypy 1.9.0 (compiled: yes)
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files):
; We don't run mypy in the CI. This is just to help anyone who would like to use it manually.; Namely, the mypy_primer tool.[mypy]show_column_numbers = true
mypy_path = $MYPY_CONFIG_FILE_DIR/typings
implicit_reexport = true
strict = true
; Implicit return types !check_untyped_defs = true
disallow_untyped_calls = false
disallow_untyped_defs = false
disallow_incomplete_defs = false
disable_error_code = return
; exclude mypyc buildexclude = .*(build)/.*
; Auto-generated code, not much we can do there[mypy-gen.*]disable_error_code = attr-defined, arg-type
; Of course my stubs are going to be incomplete. Otherwise they'd be on typeshed!; Mypy becomes really whack with its errors inside these stubs though[mypy-scipy.*]disable_error_code = attr-defined, import-untyped
Python version used: 3.11.6
The text was updated successfully, but these errors were encountered:
Bug Report
A method returning only boolean values is inferred as returning
Any
To Reproduce
See the following minimal example:
The real-world example is as such:
Which is much more readable than a boolean expression. But even that surprisingly is inferred as Any:
Expected Behavior
The return type should be inferred as
bool
. EvenLiteral[True, False]
orLiteral[True, False] | bool
would be fine.Actual Behavior
Return type is inferred as
Any
Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: