Hello,
I would like to ask/report bug whether it is possible to have (enum.IntFlag)().name as type None or if it is incorrectly typed as str|None.
Bug Report
Looks like (enum.IntFlag)().name is typed as str|None but I think it should be just str.
To Reproduce
import enum
class ListType(enum.IntFlag):
ABC = enum.auto()
DEF = enum.auto()
GHI = enum.auto()
def get_names(self) -> list[str]:
to_return = []
for e in ListType:
reveal_type(e) # note: Revealed type is "__main__.ListType"
reveal_type(e.name) # note: Revealed type is "Union[builtins.str, None]"
to_return.append(e.name)
return to_return # error: Incompatible return value type (got "list[str | None]", expected "list[str]") [return-value]
https://onlinegdb.com/Rsv6ryZzf
https://mypy-play.net/?mypy=latest&python=3.11&gist=61af435c15e57ce5221abada2221008a
Expected Behavior
I would expect that (enum.IntFlag)().name is always string.
Success: no issues found in 1 source file
Actual Behavior
main.py:19: error: Incompatible return value type (got "list[str | None]", expected "list[str]") [return-value]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.5.1
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini (and other config files):
- Python version used: 3.9, 3.10, 3.11
Hello,
I would like to ask/report bug whether it is possible to have
(enum.IntFlag)().nameas type None or if it is incorrectly typed asstr|None.Bug Report
Looks like
(enum.IntFlag)().nameis typed asstr|Nonebut I think it should be juststr.To Reproduce
https://onlinegdb.com/Rsv6ryZzf
https://mypy-play.net/?mypy=latest&python=3.11&gist=61af435c15e57ce5221abada2221008a
Expected Behavior
I would expect that
(enum.IntFlag)().nameis always string.Actual Behavior
Your Environment
mypy.ini(and other config files):