(
self,
registry: _RegistryType,
cls_: Type[_O],
dict_: _ClassDict,
)
| 952 | single: bool |
| 953 | |
| 954 | def __init__( |
| 955 | self, |
| 956 | registry: _RegistryType, |
| 957 | cls_: Type[_O], |
| 958 | dict_: _ClassDict, |
| 959 | ): |
| 960 | # grab class dict before the instrumentation manager has been added. |
| 961 | # reduces cycles |
| 962 | self.clsdict_view = ( |
| 963 | util.immutabledict(dict_) if dict_ else util.EMPTY_DICT |
| 964 | ) |
| 965 | super().__init__(registry, cls_) |
| 966 | self.registry = registry |
| 967 | self.persist_selectable = None |
| 968 | |
| 969 | self.collected_attributes = {} |
| 970 | self.collected_annotations = {} |
| 971 | self.declared_columns = util.OrderedSet() |
| 972 | self.column_ordering = {} |
| 973 | self.column_copies = {} |
| 974 | self.single = False |
| 975 | self.dataclass_setup_arguments = dca = getattr( |
| 976 | self.cls, "_sa_apply_dc_transforms", None |
| 977 | ) |
| 978 | |
| 979 | self.allow_unmapped_annotations = getattr( |
| 980 | self.cls, "__allow_unmapped__", False |
| 981 | ) or bool(self.dataclass_setup_arguments) |
| 982 | |
| 983 | self.is_dataclass_prior_to_mapping = cld = dataclasses.is_dataclass( |
| 984 | cls_ |
| 985 | ) |
| 986 | |
| 987 | sdk = _get_immediate_cls_attr(cls_, "__sa_dataclass_metadata_key__") |
| 988 | |
| 989 | # we don't want to consume Field objects from a not-already-dataclass. |
| 990 | # the Field objects won't have their "name" or "type" populated, |
| 991 | # and while it seems like we could just set these on Field as we |
| 992 | # read them, Field is documented as "user read only" and we need to |
| 993 | # stay far away from any off-label use of dataclasses APIs. |
| 994 | if (not cld or dca) and sdk: |
| 995 | raise exc.InvalidRequestError( |
| 996 | "SQLAlchemy mapped dataclasses can't consume mapping " |
| 997 | "information from dataclass.Field() objects if the immediate " |
| 998 | "class is not already a dataclass." |
| 999 | ) |
| 1000 | |
| 1001 | # if already a dataclass, and __sa_dataclass_metadata_key__ present, |
| 1002 | # then also look inside of dataclass.Field() objects yielded by |
| 1003 | # dataclasses.get_fields(cls) when scanning for attributes |
| 1004 | self.allow_dataclass_fields = bool(sdk and cld) |
| 1005 | |
| 1006 | self._setup_declared_events() |
| 1007 | |
| 1008 | self._scan_attributes() |
| 1009 | |
| 1010 | self._setup_dataclasses_transforms(enable_descriptor_defaults=True) |
| 1011 |
nothing calls this directly
no test coverage detected