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 erezinman
Recipients erezinman
Date 2021-05-06.11:48:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1620301699.13.0.690362805171.issue44057@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-05-06 11:48:19erezinmansetrecipients: + erezinman
2021-05-06 11:48:19erezinmansetmessageid: <1620301699.13.0.690362805171.issue44057@roundup.psfhosted.org>
2021-05-06 11:48:19erezinmanlinkissue44057 messages
2021-05-06 11:48:18erezinmancreate