Check whether __new__ comes from enum.Enum or was implemented in a subclass of enum.Enum. In the latter case, we must infer Any as long as mypy can't infer the type of _value_ from assignments in __new__. If, however, __new__ comes from a user-defined class that is not an Enum subclass
(info: TypeInfo)
| 127 | |
| 128 | |
| 129 | def _implements_new(info: TypeInfo) -> bool: |
| 130 | """Check whether __new__ comes from enum.Enum or was implemented in a |
| 131 | subclass of enum.Enum. In the latter case, we must infer Any as long as mypy can't infer |
| 132 | the type of _value_ from assignments in __new__. |
| 133 | |
| 134 | If, however, __new__ comes from a user-defined class that is not an Enum subclass (i.e. |
| 135 | the data type) this is allowed, because we should in general infer that an enum entry's |
| 136 | value has that type. |
| 137 | """ |
| 138 | type_with_new = _first(ti for ti in info.mro if ti.is_enum and ti.names.get("__new__")) |
| 139 | if type_with_new is None: |
| 140 | return False |
| 141 | return type_with_new.fullname not in ("enum.Enum", "enum.IntEnum", "enum.StrEnum") |
| 142 | |
| 143 | |
| 144 | def enum_member_callback(ctx: mypy.plugin.FunctionContext) -> Type: |
no test coverage detected
searching dependent graphs…