mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Merge pull request #1561 from PeterJCLaw/newtype-pyclass
Support accessing the py__class__ of a NewType
This commit is contained in:
@@ -413,6 +413,10 @@ class NewType(Value):
|
|||||||
self._type_value_set = type_value_set
|
self._type_value_set = type_value_set
|
||||||
self.tree_node = tree_node
|
self.tree_node = tree_node
|
||||||
|
|
||||||
|
def py__class__(self):
|
||||||
|
c, = self._type_value_set.py__class__()
|
||||||
|
return c
|
||||||
|
|
||||||
def py__call__(self, arguments):
|
def py__call__(self, arguments):
|
||||||
return self._type_value_set.execute_annotation()
|
return self._type_value_set.execute_annotation()
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,18 @@ def testnewtype2(y):
|
|||||||
y
|
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
|
# python > 2.7
|
||||||
|
|
||||||
class TestDefaultDict(typing.DefaultDict[str, int]):
|
class TestDefaultDict(typing.DefaultDict[str, int]):
|
||||||
|
|||||||
Reference in New Issue
Block a user