diff options
author | Federico Caselli <cfederico87@gmail.com> | 2021-12-22 21:45:45 +0100 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-12-30 18:07:26 -0500 |
commit | e913ec8155b64e055f3a88ca9c1bb7f112202c76 (patch) | |
tree | b0847baac43de628cd74bc2ff70cc352bbcb0270 /lib/sqlalchemy/util/typing.py | |
parent | 54875c21601eaca01e3217d5b22fab6f6cf50992 (diff) | |
download | sqlalchemy-e913ec8155b64e055f3a88ca9c1bb7f112202c76.tar.gz |
Properly type _generative, decorator, public_factory
Good new is that pylance likes it and copies over the
singature and everything.
Bad news is that mypy does not support this yet https://github.com/python/mypy/issues/8645
Other minor bad news is that non_generative is not typed. I've tried using a protocol
like the one in the comment but the signature is not ported over by pylance, so it's
probably best to just live without it to have the correct signature.
notes from mike: these three decorators are at the core of getting
the library to be typed, more good news is that pylance will
do all the things we like re: public_factory, see
https://github.com/microsoft/pyright/issues/2758#issuecomment-1002788656
.
For @_generative, we will likely move to using pep 673 once mypy
supports it which may be soon. but overall having the explicit
"return self" in the methods, while a little inconvenient, makes
the typing more straightforward and locally present in the files
rather than being decided at a distance. having "return self"
present, or not, both have problems, so maybe we will be able
to change it again if things change as far as decorator support.
As it is, I feel like we are barely squeaking by with our decorators,
the typing is already pretty out there.
Change-Id: Ic77e13fc861def76a5925331df85c0aa48d77807
References: #6810
Diffstat (limited to 'lib/sqlalchemy/util/typing.py')
-rw-r--r-- | lib/sqlalchemy/util/typing.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py index 801c4a110..e735ce531 100644 --- a/lib/sqlalchemy/util/typing.py +++ b/lib/sqlalchemy/util/typing.py @@ -1,4 +1,5 @@ from typing import Any +from typing import Callable # noqa from typing import Generic from typing import overload from typing import Type @@ -15,6 +16,12 @@ else: from typing_extensions import Protocol # noqa from typing_extensions import TypedDict # noqa +if compat.py310: + from typing import Concatenate + from typing import ParamSpec +else: + from typing_extensions import Concatenate # noqa + from typing_extensions import ParamSpec # noqa if compat.py311: from typing import NotRequired # noqa |