Why does the SQLAlchemy code distinguish between bound=object and bound=Any? #9835
-
I'm working on a Flask-SQLAlchemy PR to improve the typing, and am basing some types on how SQLAlchemy does it. I'm puzzled over this:
In what situations does _OO not work? It seems that _O is used in most of the signatures. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I recall coming across this difference but i dont recall what the error was, it was also an older version of mypy. I will say that typing tools are very liberal when they see Let's try right now to see if theres any difference; first apply this diff: diff --git a/lib/sqlalchemy/orm/_typing.py b/lib/sqlalchemy/orm/_typing.py
index 36dc6ddb9c..c433d98a72 100644
--- a/lib/sqlalchemy/orm/_typing.py
+++ b/lib/sqlalchemy/orm/_typing.py
@@ -55,7 +55,7 @@ _T_co = TypeVar("_T_co", bound=Any, covariant=True)
# I would have preferred this were bound=object however it seems
# to not travel in all situations when defined in that way.
-_O = TypeVar("_O", bound=Any)
+_O = TypeVar("_O", bound=object)
"""The 'ORM mapped object' type.
"""
then let's run the pep-484 suite - here's the errors we get:
reverting that patch and running pep-484 again the errors go away. |
Beta Was this translation helpful? Give feedback.
-
Last one is definitely the best error :/ |
Beta Was this translation helpful? Give feedback.
I recall coming across this difference but i dont recall what the error was, it was also an older version of mypy. I will say that typing tools are very liberal when they see
Any
in a different way when they see any other type, evenobject
which is the base type of literally everything in the Python interpreter.Let's try right now to see if theres any difference; first apply this diff: