Skip to content

Commit a908a42

Browse files
committed
attempt to fix foundational issue in stubs
In the second revision of stubs, way in the beginning, if I'm reading correctly this commit: b7f469c, the basemost class of QueryableAttribute got lost. Since then, Mapped and QueryableAttribute have been treated as Any. All the revs of the plugin, the stubs, etc. have been based off this erroneous assumption. It's likely too late to change it as it would introduce a lot of new risk. however, let's put up a patch that's passing for the SQLAlchemy side, with some mypy plugin changes on that end (yikes), then see if we can get this side working, then look at what we have.
1 parent 8635071 commit a908a42

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

.github/workflows/run-test.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ jobs:
1717
python-version:
1818
- "3.10"
1919
sqlalchemy:
20-
- sqla_release
21-
- sqla_rel_1_4
20+
# - sqla_release
21+
# - sqla_rel_1_4
22+
- sqla_fix_mypy
2223

2324
fail-fast: false
2425

sqlalchemy-stubs/orm/attributes.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ class QueryableAttribute(
5050
traversals.HasCopyInternals,
5151
roles.JoinTargetRole,
5252
roles.OnClauseRole,
53+
roles.OrderByRole,
54+
roles.DDLConstraintColumnRole,
5355
sql_base.Immutable,
54-
sql_base.MemoizedHasCacheKey,
5556
):
5657
is_attribute: bool = ...
5758
class_: Any = ...

sqlalchemy-stubs/orm/relationships.pyi

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ from typing import Union
1111

1212
from typing_extensions import Literal
1313

14-
from . import TypingBackrefResult as _BackrefResult
1514
from . import attributes as attributes
15+
from . import TypingBackrefResult as _BackrefResult
1616
from .base import state_str as state_str
1717
from .interfaces import MANYTOMANY as MANYTOMANY
1818
from .interfaces import MANYTOONE as MANYTOONE
@@ -47,13 +47,13 @@ _T = TypeVar("_T")
4747
_OrderByArgument = Union[
4848
Literal[False],
4949
str,
50-
elements.ColumnElement[Any],
51-
Sequence[elements.ColumnElement[Any]],
50+
roles.OrderByRole,
51+
Sequence[roles.OrderByRole],
5252
Callable[
5353
[],
5454
Union[
55-
elements.ColumnElement[Any],
56-
Sequence[elements.ColumnElement[Any]],
55+
roles.OrderByRole,
56+
Sequence[roles.OrderByRole],
5757
],
5858
],
5959
]
@@ -133,7 +133,6 @@ class RelationshipProperty(StrategizedProperty[_T]):
133133
sync_backref: Optional[Any] = ...,
134134
) -> None: ...
135135
def instrument_class(self, mapper: Any) -> None: ...
136-
137136
class Comparator(PropComparator):
138137
prop: Any = ...
139138
def __init__(
@@ -161,7 +160,6 @@ class RelationshipProperty(StrategizedProperty[_T]):
161160
def __ne__(self, other: Any) -> Any: ...
162161
@util.memoized_property
163162
def property(self): ...
164-
165163
def merge(
166164
self,
167165
session: Any,

sqlalchemy-stubs/sql/functions.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing import Union
99

1010
from typing_extensions import Protocol
1111

12+
from . import roles
1213
from . import sqltypes
1314
from . import type_api
1415
from .base import ColumnCollection
@@ -36,7 +37,7 @@ _T_co = TypeVar("_T_co", covariant=True)
3637
_TE = TypeVar("_TE", bound=type_api.TypeEngine[Any])
3738
_FE = TypeVar("_FE", bound=FunctionElement[Any])
3839

39-
_OverByType = Union[ClauseElement, str]
40+
_OverByType = Union[ClauseElement, str, roles.OrderByRole]
4041

4142
def register_function(
4243
identifier: str, fn: Any, package: str = ...

sqlalchemy-stubs/sql/schema.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ class ForeignKey(DialectKWArgs, SchemaItem):
265265
match: Optional[str] = ...
266266
def __init__(
267267
self,
268-
column: Union[Column[Any], str],
268+
column: Union[roles.DDLConstraintColumnRole, str],
269269
_constraint: Optional[ForeignKeyConstraint] = ...,
270270
use_alter: bool = ...,
271271
name: Optional[str] = ...,

test/files/column_operators_binops.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class A:
2727

2828
eq1: "ColumnElement[Boolean]" = A.id == A.id
2929
eq2: "ColumnElement[Boolean]" = A.id == 1
30-
eq3: "ColumnElement[Boolean]" = 1 == A.id
30+
eq3: "bool" = 1 == A.id
3131

3232
ne1: "ColumnElement[Boolean]" = A.id != A.id
3333
ne2: "ColumnElement[Boolean]" = A.id != 1
34-
ne3: "ColumnElement[Boolean]" = 1 != A.id
34+
ne3: "bool" = 1 != A.id
3535

3636
gt1: "ColumnElement[Boolean]" = A.id < A.id
3737
gt2: "ColumnElement[Boolean]" = A.id < 1

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
; envlist = py
44

55
SQLA_REPO = {env:SQLA_REPO:https://github.com/sqlalchemy/sqlalchemy.git}
6-
SQLA_REF = {env:SQLA_REF:rel_1_4}
6+
SQLA_REF = {env:SQLA_REF:fix_mypy}
77

88
[testenv]
99

0 commit comments

Comments
 (0)