Support accessing the py__class__ of a NewType

The test here is a bit contrived, the actual place I found this
was in using a NewType as a type within a NamedTuple. However due
to https://github.com/davidhalter/jedi/issues/1560 that currently
also fails for other reasons. This still feels useful to fix on
its own though.
This commit is contained in:
Peter Law
2020-04-26 00:55:27 +01:00
parent dca505c884
commit 612fd23777
2 changed files with 16 additions and 0 deletions

View File

@@ -413,6 +413,10 @@ class NewType(Value):
self._type_value_set = type_value_set
self.tree_node = tree_node
def py__class__(self):
c, = self._type_value_set.py__class__()
return c
def py__call__(self, arguments):
return self._type_value_set.execute_annotation()

View File

@@ -283,6 +283,18 @@ def testnewtype2(y):
y
#? []
y.
# The type of a NewType is equivalent to the type of its underlying type.
MyInt = typing.NewType('MyInt', int)
x = type(MyInt)
#? type.mro
x.mro
PlainInt = int
y = type(PlainInt)
#? type.mro
y.mro
# python > 2.7
class TestDefaultDict(typing.DefaultDict[str, int]):