This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kflu
Recipients kflu
Date 2019-09-27.18:26:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1569608797.01.0.364223398696.issue38298@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-09-27 18:26:37kflusetrecipients: + kflu
2019-09-27 18:26:37kflusetmessageid: <1569608797.01.0.364223398696.issue38298@roundup.psfhosted.org>
2019-09-27 18:26:36kflulinkissue38298 messages
2019-09-27 18:26:36kflucreate