diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-04-28 16:19:43 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-05-03 15:58:45 -0400 |
commit | 1fa3e2e3814b4d28deca7426bb3f36e7fb515496 (patch) | |
tree | 9b07b8437b1190227c2e8c51f2e942936721000f /lib/sqlalchemy/util/typing.py | |
parent | 6a496a5f40efe6d58b09eeca9320829789ceaa54 (diff) | |
download | sqlalchemy-1fa3e2e3814b4d28deca7426bb3f36e7fb515496.tar.gz |
pep484: attributes and related
also implements __slots__ for QueryableAttribute,
InstrumentedAttribute, Relationship.Comparator.
Change-Id: I47e823160706fc35a616f1179a06c7864089e5b5
Diffstat (limited to 'lib/sqlalchemy/util/typing.py')
-rw-r--r-- | lib/sqlalchemy/util/typing.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index 4929ba1a6..a95f5ab93 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -9,6 +9,7 @@ from typing import Callable from typing import cast from typing import Dict from typing import ForwardRef +from typing import Generic from typing import Iterable from typing import Optional from typing import Tuple @@ -213,3 +214,41 @@ def _get_type_name(type_: Type[Any]) -> str: typ_name = getattr(type_, "_name", None) return typ_name # type: ignore + + +class DescriptorProto(Protocol): + def __get__(self, instance: object, owner: Any) -> Any: + ... + + def __set__(self, instance: Any, value: Any) -> None: + ... + + def __delete__(self, instance: Any) -> None: + ... + + +_DESC = TypeVar("_DESC", bound=DescriptorProto) + + +class DescriptorReference(Generic[_DESC]): + """a descriptor that refers to a descriptor. + + used for cases where we need to have an instance variable referring to an + object that is itself a descriptor, which typically confuses typing tools + as they don't know when they should use ``__get__`` or not when referring + to the descriptor assignment as an instance variable. See + sqlalchemy.orm.interfaces.PropComparator.prop + + """ + + def __get__(self, instance: object, owner: Any) -> _DESC: + ... + + def __set__(self, instance: Any, value: _DESC) -> None: + ... + + def __delete__(self, instance: Any) -> None: + ... + + +# $def ro_descriptor_reference(fn: Callable[]) |