Skip to content

attempt to fix foundational issue in stubs #249

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

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion sqlalchemy-stubs/orm/attributes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,18 @@ class QueryableAttribute(
traversals.HasCopyInternals,
roles.JoinTargetRole,
roles.OnClauseRole,
roles.OrderByRole,
roles.DDLConstraintColumnRole,
sql_base.Immutable,
sql_base.MemoizedHasCacheKey,
# NOTE: this is something we would rather not have here, however, due
# to a long-standing error that was here, QueryableAttribute and therefore
# Mapped were acting like Any for quite a long time. In SQLAlchemy 1.4,
# in order to remove this Any and have our current tests pass,
# adjustments to mypy plugin are needed which are present in
# SQLAlchemy 2a53f70eeed0c39ff13e0c57086443e8714c8142 as of
# 1.4.47 (if released). As this is all legacy stuff, for the moment
# we are leaving Any here to avoid regressions.
Any,
):
is_attribute: bool = ...
class_: Any = ...
Expand Down
12 changes: 5 additions & 7 deletions sqlalchemy-stubs/orm/relationships.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ from typing import Union

from typing_extensions import Literal

from . import TypingBackrefResult as _BackrefResult
from . import attributes as attributes
from . import TypingBackrefResult as _BackrefResult
from .base import state_str as state_str
from .interfaces import MANYTOMANY as MANYTOMANY
from .interfaces import MANYTOONE as MANYTOONE
Expand Down Expand Up @@ -47,13 +47,13 @@ _T = TypeVar("_T")
_OrderByArgument = Union[
Literal[False],
str,
elements.ColumnElement[Any],
Sequence[elements.ColumnElement[Any]],
roles.OrderByRole,
Sequence[roles.OrderByRole],
Callable[
[],
Union[
elements.ColumnElement[Any],
Sequence[elements.ColumnElement[Any]],
roles.OrderByRole,
Sequence[roles.OrderByRole],
],
],
]
Expand Down Expand Up @@ -133,7 +133,6 @@ class RelationshipProperty(StrategizedProperty[_T]):
sync_backref: Optional[Any] = ...,
) -> None: ...
def instrument_class(self, mapper: Any) -> None: ...

class Comparator(PropComparator):
prop: Any = ...
def __init__(
Expand Down Expand Up @@ -161,7 +160,6 @@ class RelationshipProperty(StrategizedProperty[_T]):
def __ne__(self, other: Any) -> Any: ...
@util.memoized_property
def property(self): ...

def merge(
self,
session: Any,
Expand Down
3 changes: 2 additions & 1 deletion sqlalchemy-stubs/sql/functions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ from typing import Union

from typing_extensions import Protocol

from . import roles
from . import sqltypes
from . import type_api
from .base import ColumnCollection
Expand Down Expand Up @@ -36,7 +37,7 @@ _T_co = TypeVar("_T_co", covariant=True)
_TE = TypeVar("_TE", bound=type_api.TypeEngine[Any])
_FE = TypeVar("_FE", bound=FunctionElement[Any])

_OverByType = Union[ClauseElement, str]
_OverByType = Union[ClauseElement, str, roles.OrderByRole]

def register_function(
identifier: str, fn: Any, package: str = ...
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy-stubs/sql/schema.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class ForeignKey(DialectKWArgs, SchemaItem):
match: Optional[str] = ...
def __init__(
self,
column: Union[Column[Any], str],
column: Union[roles.DDLConstraintColumnRole, str],
_constraint: Optional[ForeignKeyConstraint] = ...,
use_alter: bool = ...,
name: Optional[str] = ...,
Expand Down
6 changes: 4 additions & 2 deletions test/files/column_operators_binops.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ class A:

eq1: "ColumnElement[Boolean]" = A.id == A.id
eq2: "ColumnElement[Boolean]" = A.id == 1
eq3: "ColumnElement[Boolean]" = 1 == A.id
# this changes based on QueryableAttribute(Any) lineage
# eq3: "bool" = 1 == A.id

ne1: "ColumnElement[Boolean]" = A.id != A.id
ne2: "ColumnElement[Boolean]" = A.id != 1
ne3: "ColumnElement[Boolean]" = 1 != A.id
# this changes based on QueryableAttribute(Any) lineage
# ne3: "bool" = 1 != A.id

gt1: "ColumnElement[Boolean]" = A.id < A.id
gt2: "ColumnElement[Boolean]" = A.id < 1
Expand Down