Message353386
This is a new regression in Python3.7.
Create the following file as `test.py`
```
# test.py
import typing as t
T = t.TypeVar("T")
class BaseOfGeneric:
@classmethod
def f(cls):
# when called from an instantiated generic type, e.g.,
# `MyList[int]`, expect `cls` to be the GenericAlias with its type
# argument already insteantiated
print(f"current class is {cls}")
print(f"current class's type: {type(cls)}")
class MyList(t.List[T], BaseOfGeneric):
pass
MyIntList = MyList[int]
MyIntList.f()
```
Run with Python3.6:
>>> python3.6 ./test.py
current class is __main__.MyList[int]
^^^ as expected
current class's type: <class 'typing.GenericMeta'>
EXPECTED BEHAVIOR: The outcome is expected: `cls` of `BaseOfGeneric.f` should be `MyList` **with** type argument `int`
However this is wrong in Python3.7:
>>> python3.7 ./test.py
current class is <class '__main__.MyList'>
^^^^^^^^^^^^^^^ type argument is LOST !!!
current class's type: <class 'type'>
Note that `cls` of `BaseOfGeneric.f` has lost the type argument `int`! It is not expected. |
|
Date |
User |
Action |
Args |
2019-09-27 18:26:37 | kflu | set | recipients:
+ kflu |
2019-09-27 18:26:37 | kflu | set | messageid: <1569608797.01.0.364223398696.issue38298@roundup.psfhosted.org> |
2019-09-27 18:26:36 | kflu | link | issue38298 messages |
2019-09-27 18:26:36 | kflu | create | |
|