-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement pep 646 for select() / query() / Row / Result / execute() / scalars() #7516
Comments
From the pyright readme it seems they indeed do support it: https://github.com/Microsoft/pyright#type-checking-features |
OK, change of plans, from what I am seeing. There does not seem to be pep-646 implemented anywhere. Even though the pep says it's in Python 3.10, nope: $ python
Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> typing.TypeVarTuple
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'typing' has no attribute 'TypeVarTuple'
>>> import typing_extensions
>>> typing_extensions.TypeVarTuple
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'typing_extensions' has no attribute 'TypeVarTuple' additionally the examples given don't even compile in Python:
taht's using this example: from typing import TypeVar, Generic, Tuple, NewType
from typing_extensions import TypeVarTuple
Shape = TypeVarTuple("Shape")
Height = NewType('Height', int)
Width = NewType('Width', int)
class Array(Generic[*Shape]):
def __init__(self, shape: Tuple[*Shape]):
self._shape: Tuple[*Shape] = shape
def get_shape(self) -> Tuple[*Shape]:
return self._shape
shape = (Height(480), Width(640))
x: Array[Height, Width] = Array(shape)
y = abs(x) # Inferred type is Array[Height, Width]
z = x + x # ... is Array[Height, Width] so....even if they did implement this in 3.11, i dont know what we're going to do because the syntax isn't even supported?! |
i've asked microsoft/pyright#2780 |
Co basically it's supported but you cannot actually use it anywhere because python doesn't support it? |
i got a POC to work on the above pyright issue. blows up mypy obviously |
Oh nice, is it on gerrit already? |
not yet. it "works" but doesnt really do what we need it to, and i dont know if any of these PEPs have plans in mind that would allow it. ill put it up in a moment |
Mike Bayer has proposed a fix for this issue in the main branch: attempt pep 646 https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3446 |
OK based on what we see at python/typing#1001, the answer is, "can't be done". I'm not really sure what the usefulness of pep646 is at the moment if the types within the tuples are inaccessible. For the moment I dont see any way of SQLAlchemy statements being typed in a way that is meaningful in terms of the kind of result/ row they produce. I know SQLModel does this really hacky trick to try to give users the illusion that select statements are typed to their contents, though I'm not sure that would even be workable unless you also have a more automatic version of session.execute(), then sqlalchemy-stubs is also doing a version of it. For those particular hacks, maybe we can get typing for a Query object and a select() object against a single ORM entity, then have it translate out to session.scalars() / query.all(). That is we support single-element ScalarResult etc. would be better than nothing. |
shame :( |
this will be done and tracked in #10635 |
pep 646 has been out for over a year and is in python 3.10
https://www.python.org/dev/peps/pep-0646/#summary-examples
i dont think mypy has support . however, maybe pylance / pyright do. if they do, this would be great, we can just go for it. this issue is moved from sqlalchemy/sqlalchemy2-stubs#1 .
The text was updated successfully, but these errors were encountered: