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
mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')"
Expected Behavior
Should accept that a is a logging.Handler
Actual Behavior
<string>:1: error: Incompatible types in assignment (expression has type "object", variable has type "Handler")
Similar examples that do work
Hard-coding the condition
mypy -c "import logging; a:logging.Handler = logging.StreamHandler() if False else logging.FileHandler('test.log')"
Success: no issues found in 1 source file
Using integers instead of logging.Handlers
mypy -c "b=False; a:int = 0 if b else 1"
Success: no issues found in 1 source file
Your Environment
Mypy version used: 0.971 (compiled: no)
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): None
Python version used: 3.9.13
Operating system and version: Windows 10
The text was updated successfully, but these errors were encountered:
To Reproduce
mypy -c "import logging; b=False; a:logging.Handler = logging.StreamHandler() if b else logging.FileHandler('test.log')"
Expected Behavior
Should accept that
a
is alogging.Handler
Actual Behavior
<string>:1: error: Incompatible types in assignment (expression has type "object", variable has type "Handler")
Similar examples that do work
Hard-coding the condition
Using integers instead of
logging.Handler
sYour Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: