New submission from Cheuk Ting Ho <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue44710>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com