-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-ternary-expressiona if b else ca if b else c
Description
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 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
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-ternary-expressiona if b else ca if b else c