diff options
author | mike bayer <mike_mp@zzzcomputing.com> | 2022-05-03 20:24:20 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-05-03 20:24:20 +0000 |
commit | 0cb54010d86493168cc763b836c0a71429b26c1b (patch) | |
tree | 583b489242564e78efe0b2519723e094b057ea14 /lib/sqlalchemy/util/typing.py | |
parent | 675c3e17f7fcccb7534c46adb56529fc3ddd8dbf (diff) | |
parent | 1fa3e2e3814b4d28deca7426bb3f36e7fb515496 (diff) | |
download | sqlalchemy-0cb54010d86493168cc763b836c0a71429b26c1b.tar.gz |
Merge "pep484: attributes and related" into main
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[]) |