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 John Lennon
Recipients John Lennon
Date 2019-10-13.08:31:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1570955483.97.0.910944150391.issue38459@roundup.psfhosted.org>
In-reply-to
Content
Given the file `example.py` with the following contents:


```python

from typing import Generic, TypeVar

KT = TypeVar("KT")
VT = TypeVar("VT")


class GenericMapping(Generic[KT, VT]):
    pass


class SomeImplMapping(GenericMapping):
    pass


a: GenericMapping[int, float]
b: SomeImplMapping[int, float]
```


I would expect `SomeImplMapping` to be generic as well as `GenericMapping`. However, currently this code fails with the following error:

```sh
Traceback (most recent call last):
  File "adt.py", line 18, in <module>
    b: SomeImplMapping[int, float]
  File "/usr/local/lib/python3.7/typing.py", line 254, in inner
    return func(*args, **kwds)
  File "/usr/local/lib/python3.7/typing.py", line 841, in __class_getitem__
    _check_generic(cls, params)
  File "/usr/local/lib/python3.7/typing.py", line 204, in _check_generic
    raise TypeError(f"{cls} is not a generic class")
TypeError: <class '__main__.SomeImplMapping'> is not a generic class
```


If I understand everything correctly, that's because `typing` doesn't check bases of the class to have `__parameters__` attribute:

https://github.com/python/cpython/blob/master/Lib/typing.py#L210

I did not found the restriction that only direct childs of `Generic[..]` class can be generic in the docs, so I think this is a bug.
History
Date User Action Args
2019-10-13 08:31:24John Lennonsetrecipients: + John Lennon
2019-10-13 08:31:23John Lennonsetmessageid: <1570955483.97.0.910944150391.issue38459@roundup.psfhosted.org>
2019-10-13 08:31:23John Lennonlinkissue38459 messages
2019-10-13 08:31:23John Lennoncreate