Message393085
The following behavior was witnessed in v3.6 & v3.8.
When deriving from a Generic base class, there's an inconsistency in the order of operation within the `__new__()` function between the case of deriving WITH generic-argument specification and WITHOUT.
It might be best explained in the following example:
```
import typing
T = typing.TypeVar('T')
class Base(typing.Generic[T]):
some_attribute: typing.Any
def __init_subclass__(cls, **kwargs):
assert hasattr(cls, 'some_attribute')
class Class1(Base): # OK
some_attribute = 123
class Class2(Base[int]): # AssertionError
some_attribute = 123
```
In this examples, the base class implements `__init_subclass__` to ensure that sublclasses define an attribute. In the case of `Class1`, the class derives without specifying the type-arguments for the class. In that case, the `__init_subclass__` is called after the `some_attribute` is defined. In the second case, however, because I pass the `int` type-argument to the base-class, for some reason `__init_subclass__` is called BEFORE the class' definition. |
|
Date |
User |
Action |
Args |
2021-05-06 11:48:19 | erezinman | set | recipients:
+ erezinman |
2021-05-06 11:48:19 | erezinman | set | messageid: <1620301699.13.0.690362805171.issue44057@roundup.psfhosted.org> |
2021-05-06 11:48:19 | erezinman | link | issue44057 messages |
2021-05-06 11:48:18 | erezinman | create | |
|