Repository navigation
Allow E[<str>] where E is an Enum type - #2812
Conversation
| elif isinstance(left_type, TypedDictType): | ||
| return self.visit_typeddict_index_expr(left_type, e.index) | ||
| elif (isinstance(left_type, CallableType) | ||
| and left_type.is_type_obj() and left_type.type_object()): |
There was a problem hiding this comment.
It looks like this already works correctly, but I think it would be safer to check for left_type.type_object().is_enum
| string_type = UnionType.make_union([string_type, | ||
| self.named_type('builtins.unicode')]) | ||
| self.chk.check_subtype(self.accept(index), string_type, context, | ||
| "Enum index should be a string", "actual index type") |
There was a problem hiding this comment.
I think it would be better to have a test that triggers this error.
|
Perhaps I am confusing things, but I think this can (and probably should?) be fixed after #2475 is merged, by augmenting EnumMeta and without further special casing. |
|
I actually looked into basing this on #2475, but there's a catch: because of the special-casing of It might be possible to differentiate on the basis of whether |
670a34c to
d829376
Compare
Fixes #1381