def local_attributes_for_class():
for name, obj in vars(cls).items():
- yield name, obj
+ yield name, obj, False
else:
field_names = set()
field_names.add(field.name)
yield field.name, _as_dc_declaredattr(
field.metadata, sa_dataclass_metadata_key
- )
+ ), True
for name, obj in vars(cls).items():
if name not in field_names:
- yield name, obj
+ yield name, obj, False
return local_attributes_for_class
local_attributes_for_class, attribute_is_overridden
)
- for name, obj in local_attributes_for_class():
+ for name, obj, is_dataclass in local_attributes_for_class():
if name == "__mapper_args__":
check_decl = _check_declared_props_nocascade(
obj, name, cls
# however, check for some more common mistakes
else:
self._warn_for_decl_attributes(base, name, obj)
- elif name not in dict_ or dict_[name] is not obj:
+ elif is_dataclass and (
+ name not in dict_ or dict_[name] is not obj
+ ):
# here, we are definitely looking at the target class
# and not a superclass. this is currently a
# dataclass-only path. if the name is only
# a dataclass field and isn't in local cls.__dict__,
# put the object there.
-
# assert that the dataclass-enabled resolver agrees
# with what we are seeing
+
assert not attribute_is_overridden(name, obj)
if _is_declarative_props(obj):
column_copies = self.column_copies
# copy mixin columns to the mapped class
- for name, obj in attributes_for_class():
+ for name, obj, is_dataclass in attributes_for_class():
if isinstance(obj, Column):
if attribute_is_overridden(name, obj):
# if column has been overridden
assert not hasattr(Foo, "data_hybrid")
+ def test_classes_can_override_new(self):
+ class MyTable(Base):
+ __tablename__ = "my_table"
+ id = Column(Integer, primary_key=True)
+
+ def __new__(cls, *args, **kwargs):
+ return object.__new__(cls)
+
+ def some_method(self):
+ pass
+
+ @staticmethod
+ def some_static_method(self):
+ pass
+
+ mt = MyTable(id=5)
+ eq_(mt.id, 5)
+
@testing.requires.python36
def test_kw_support_in_declarative_meta_init(self):
# This will not fail if DeclarativeMeta __init__ supports **kw