[New-bugs-announce] [issue44710] Unexpected behavior in empty class with pass (Python 3.7.3)

Cheuk Ting Ho report at bugs.python.org
Thu Jul 22 12:35:42 EDT 2021


New submission from Cheuk Ting Ho <cheukting.ho at gmail.com>:

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.

----------
components: C API
messages: 397988
nosy: Cheukting
priority: normal
severity: normal
status: open
title: Unexpected behavior in empty class with pass (Python 3.7.3)
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44710>
_______________________________________


More information about the New-bugs-announce mailing list