Title: Unexpected behavior in empty class with pass (Python 3.7.3)
Type: behavior Stage: resolved
Components: C API Versions: Python 3.7
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Cheukting, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-07-22 16:35 by Cheukting, last changed 2021-07-23 10:38 by Cheukting. This issue is now closed.

Messages (3)
msg397988 - (view) Author: Cheuk Ting Ho (Cheukting) Date: 2021-07-22 16:35
Demo example:

class MyType(type):
    def __init__(cls, name, bases, nmspc):

        if "__annotations__" in nmspc:
            annotations = nmspc["__annotations__"]
            nmspc["__annotations__"] = {}
            annotations = nmspc["__annotations__"]

        for parent in bases:
            base_annotations = (
                parent.__annotations__ if hasattr(parent, "__annotations__") else {}

        super().__init__(name, bases, nmspc)

class Coordinate(metaclass=MyType):
    x: float
    y: float

class Address(metaclass=MyType):
    street: str
    country: str

class Location(Address, Coordinate):

class Location2(Address, Coordinate):
    name: str


{'street': <class 'str'>, 'country': <class 'str'>}
{'name': <class 'str'>, 'street': <class 'str'>, 'country': <class 'str'>, 'x': <class 'float'>, 'y': <class 'float'>}

Was expecting the two print to be only different by 'name': <class 'str'> but the `Location fails to inherit the attribute from `Coordinate`. Not the case for `Location2`

*it's my first time submitting an issue, please kindly tell me what to do if I am not doing the right thing.
msg397989 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-07-22 18:00
Because super().__init__(name, bases, nmspc) does not have any effect. Type is created by the metaclass' __new__ method, and the __init__ method is virtually no-op.
msg398044 - (view) Author: Cheuk Ting Ho (Cheukting) Date: 2021-07-23 10:38
Thank you, Serhiy for explaining that to me. I am closing it now since it is not a bug.
Date User Action Args
2021-07-23 10:38:58Cheuktingsetstatus: open -> closed

messages: + msg398044
stage: resolved
2021-07-22 18:00:18serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg397989
2021-07-22 16:35:42Cheuktingcreate