define Python-local attribute behavior options common to all :class:`.MapperProperty` objects. Currently this includes dataclass-generation arguments. .. versionadded:: 2.0
| 212 | |
| 213 | |
| 214 | class _AttributeOptions(NamedTuple): |
| 215 | """define Python-local attribute behavior options common to all |
| 216 | :class:`.MapperProperty` objects. |
| 217 | |
| 218 | Currently this includes dataclass-generation arguments. |
| 219 | |
| 220 | .. versionadded:: 2.0 |
| 221 | |
| 222 | """ |
| 223 | |
| 224 | dataclasses_init: Union[_NoArg, bool] |
| 225 | dataclasses_repr: Union[_NoArg, bool] |
| 226 | dataclasses_default: Union[_NoArg, Any] |
| 227 | dataclasses_default_factory: Union[_NoArg, Callable[[], Any]] |
| 228 | dataclasses_compare: Union[_NoArg, bool] |
| 229 | dataclasses_kw_only: Union[_NoArg, bool] |
| 230 | dataclasses_hash: Union[_NoArg, bool, None] |
| 231 | dataclasses_dataclass_metadata: Union[_NoArg, Mapping[Any, Any], None] |
| 232 | |
| 233 | def _as_dataclass_field( |
| 234 | self, key: str, dataclass_setup_arguments: _DataclassArguments |
| 235 | ) -> Any: |
| 236 | """Return a ``dataclasses.Field`` object given these arguments.""" |
| 237 | |
| 238 | kw: Dict[str, Any] = {} |
| 239 | if self.dataclasses_default_factory is not _NoArg.NO_ARG: |
| 240 | kw["default_factory"] = self.dataclasses_default_factory |
| 241 | if self.dataclasses_default is not _NoArg.NO_ARG: |
| 242 | kw["default"] = self.dataclasses_default |
| 243 | if self.dataclasses_init is not _NoArg.NO_ARG: |
| 244 | kw["init"] = self.dataclasses_init |
| 245 | if self.dataclasses_repr is not _NoArg.NO_ARG: |
| 246 | kw["repr"] = self.dataclasses_repr |
| 247 | if self.dataclasses_compare is not _NoArg.NO_ARG: |
| 248 | kw["compare"] = self.dataclasses_compare |
| 249 | if self.dataclasses_kw_only is not _NoArg.NO_ARG: |
| 250 | kw["kw_only"] = self.dataclasses_kw_only |
| 251 | if self.dataclasses_hash is not _NoArg.NO_ARG: |
| 252 | kw["hash"] = self.dataclasses_hash |
| 253 | if self.dataclasses_dataclass_metadata is not _NoArg.NO_ARG: |
| 254 | kw["metadata"] = self.dataclasses_dataclass_metadata |
| 255 | |
| 256 | if "default" in kw and callable(kw["default"]): |
| 257 | # callable defaults are ambiguous. deprecate them in favour of |
| 258 | # insert_default or default_factory. #9936 |
| 259 | warn_deprecated( |
| 260 | f"Callable object passed to the ``default`` parameter for " |
| 261 | f"attribute {key!r} in a ORM-mapped Dataclasses context is " |
| 262 | "ambiguous, " |
| 263 | "and this use will raise an error in a future release. " |
| 264 | "If this callable is intended to produce Core level INSERT " |
| 265 | "default values for an underlying ``Column``, use " |
| 266 | "the ``mapped_column.insert_default`` parameter instead. " |
| 267 | "To establish this callable as providing a default value " |
| 268 | "for instances of the dataclass itself, use the " |
| 269 | "``default_factory`` dataclasses parameter.", |
| 270 | "2.0", |
| 271 | ) |
no outgoing calls
no test coverage detected