(self, instance: Optional[object], owner: Any)
| 270 | return util.get_annotations(self.fget).get("return") |
| 271 | |
| 272 | def __get__(self, instance: Optional[object], owner: Any) -> Any: |
| 273 | # the declared_attr needs to make use of a cache that exists |
| 274 | # for the span of the declarative scan_attributes() phase. |
| 275 | # to achieve this we look at the class manager that's configured. |
| 276 | |
| 277 | # note this method should not be called outside of the declarative |
| 278 | # setup phase |
| 279 | |
| 280 | cls = owner |
| 281 | manager = attributes.opt_manager_of_class(cls) |
| 282 | if manager is None: |
| 283 | if not re.match(r"^__.+__$", self.fget.__name__): |
| 284 | # if there is no manager at all, then this class hasn't been |
| 285 | # run through declarative or mapper() at all, emit a warning. |
| 286 | util.warn( |
| 287 | "Unmanaged access of declarative attribute %s from " |
| 288 | "non-mapped class %s" % (self.fget.__name__, cls.__name__) |
| 289 | ) |
| 290 | return self.fget(cls) |
| 291 | elif manager.is_mapped: |
| 292 | # the class is mapped, which means we're outside of the declarative |
| 293 | # scan setup, just run the function. |
| 294 | return self.fget(cls) |
| 295 | |
| 296 | # here, we are inside of the declarative scan. use the registry |
| 297 | # that is tracking the values of these attributes. |
| 298 | declarative_scan = manager.declarative_scan() |
| 299 | |
| 300 | # assert that we are in fact in the declarative scan |
| 301 | assert declarative_scan is not None |
| 302 | |
| 303 | reg = declarative_scan.declared_attr_reg |
| 304 | |
| 305 | if self in reg: |
| 306 | return reg[self] |
| 307 | else: |
| 308 | reg[self] = obj = self.fget(cls) |
| 309 | return obj |
| 310 | |
| 311 | |
| 312 | class _declared_directive(_declared_attr_common, Generic[_T]): |
nothing calls this directly
no test coverage detected