New submission from Kefei Lu <klu...@gmail.com>:
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. ---------- messages: 353386 nosy: kflu priority: normal severity: normal status: open title: Base class of generic type has wrong `cls` argument in classmethods type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38298> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com