Support bool with Literal in --warn-unreachable by kreathon · Pull Request #15645 · python/mypy (original) (raw)
MyPy Primer Analysis
- steam/package.py:396: error: Return value expected [return-value]
if self.flags & LicenseFlag.Expired:
return
if self.time_limit is None: <- This code is unreachable
return <- 396
return self.time_limit - self.time_used
self.flags
is an Instance of LicenceFlag
(which inherits from Flags
, which inherits from IntEnum
).
See below for an explanation of IntEnum
.
- steam/state.py:2565: error: Item "None" of "Language | None" has no attribute "api_name" [union-attr]
player.GetGameAchievementsRequest(appid=app_id, language=(self.language or language).api_name)
The type of language is Language | None
and the type of self.language
is Language
(which inherits from IntEnum
).
See below for an explanation of IntEnum
.
IntEnum
This class is a custom enum implementation which has:
def __bool__(self) -> Literal[True]:
return True # an enum member with a zero value would return False otherwise
I am confused by this comment, because:
>>> bool(LicenseFlag.NONE)
True
>>> bool(LicenseFlag.Renew)
True
With:
class LicenseFlag(Flags):
"""Flags for a license."""
NONE = 0
"""No flags."""
Renew = 1 << 0
...
I am not sure if this is a bug, or I am missing something ...
Edit: I will ask the steam.py
maintainer.
Edit 2: Both issues were discussed on the steam.py
Discord:
self.flags & LicenseFlag.Expired
creates a newLicenseFlag
which will evaluate to True againself.language or language
should belanguage or self.language
So the change already found two bugs 🎉