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 Cheukting
Recipients Cheukting
Date 2021-07-22.16:35:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1626971742.78.0.379614893398.issue44710@roundup.psfhosted.org>
In-reply-to
Content
Demo example:

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

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

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

        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):
    pass


class Location2(Address, Coordinate):
    name: str


print(Location.__annotations__)
print(Location2.__annotations__)
================
Output:

{'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.
History
Date User Action Args
2021-07-22 16:35:42Cheuktingsetrecipients: + Cheukting
2021-07-22 16:35:42Cheuktingsetmessageid: <1626971742.78.0.379614893398.issue44710@roundup.psfhosted.org>
2021-07-22 16:35:42Cheuktinglinkissue44710 messages
2021-07-22 16:35:42Cheuktingcreate