Skip to content

Commit aeb8785

Browse files
authored
attempt to fix foundational issue in stubs (#249)
Fixes: #236
1 parent 03ae541 commit aeb8785

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

sqlalchemy-stubs/orm/attributes.pyi

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,18 @@ 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,
56+
# NOTE: this is something we would rather not have here, however, due
57+
# to a long-standing error that was here, QueryableAttribute and therefore
58+
# Mapped were acting like Any for quite a long time. In SQLAlchemy 1.4,
59+
# in order to remove this Any and have our current tests pass,
60+
# adjustments to mypy plugin are needed which are present in
61+
# SQLAlchemy 2a53f70eeed0c39ff13e0c57086443e8714c8142 as of
62+
# 1.4.47 (if released). As this is all legacy stuff, for the moment
63+
# we are leaving Any here to avoid regressions.
64+
Any,
5565
):
5666
is_attribute: bool = ...
5767
class_: Any = ...

sqlalchemy-stubs/orm/relationships.pyi

Lines changed: 5 additions & 5 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
]

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ 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+
# this changes based on QueryableAttribute(Any) lineage
31+
# eq3: "bool" = 1 == A.id
3132

3233
ne1: "ColumnElement[Boolean]" = A.id != A.id
3334
ne2: "ColumnElement[Boolean]" = A.id != 1
34-
ne3: "ColumnElement[Boolean]" = 1 != A.id
35+
# this changes based on QueryableAttribute(Any) lineage
36+
# ne3: "bool" = 1 != A.id
3537

3638
gt1: "ColumnElement[Boolean]" = A.id < A.id
3739
gt2: "ColumnElement[Boolean]" = A.id < 1

0 commit comments

Comments
 (0)