Fix enum attributes are not members by terencehonles · Pull Request #17207 · python/mypy (original) (raw)
@hauntsaninja I got to the bottom of it, and I fixed it in a way that I figured would have the least amount of knock on effects. According to the spec _ParameterKind
should not be warning, but it should be treated as having no members. Which is what I fixed here #17207 (comment)
The issue though is that try_expanding_sum_type_to_union
code would return Never
for an enum with no members, and because Never
is also effectively the base class of all types Never
is _ParameterKind.VAR_KEYWORD
, and therefore mypy is "correctly" warning that the code is not reachable. I don't think Never
should be treated that way, but I don't want to break other things, so instead I have the try_expanding_sum_type_to_union
code check how many members it expands to, and if there are no members it doesn't expand the type and leaves it as is. This may need to stay regardless, but I think the Never is Any
may cause other subtle bugs.