-
-
Notifications
You must be signed in to change notification settings - Fork 819
👷 Replace mypy with ty in precommit
#1806
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
0251f0f
a52380b
3203f83
5d9dd59
5c9b1d5
c1b0465
732847d
2f8efa3
dc8593b
1dceaa7
02cd800
c49bf7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ | |
| from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid | ||
| from typing_extensions import deprecated | ||
|
|
||
| from ._compat import ( # type: ignore[attr-defined] | ||
| from ._compat import ( | ||
| PYDANTIC_MINOR_VERSION, | ||
| BaseConfig, | ||
| ModelMetaclass, | ||
|
|
@@ -177,7 +177,7 @@ def __init__( | |
| cascade_delete: bool | None = False, | ||
| passive_deletes: bool | Literal["all"] | None = False, | ||
| link_model: Any | None = None, | ||
| sa_relationship: RelationshipProperty | None = None, # type: ignore | ||
| sa_relationship: RelationshipProperty | None = None, | ||
| sa_relationship_args: Sequence[Any] | None = None, | ||
| sa_relationship_kwargs: Mapping[str, Any] | None = None, | ||
| ) -> None: | ||
|
|
@@ -398,7 +398,7 @@ def Field( | |
| nullable: bool | UndefinedType = Undefined, | ||
| index: bool | UndefinedType = Undefined, | ||
| sa_type: type[Any] | UndefinedType = Undefined, | ||
| sa_column: Column | UndefinedType = Undefined, # type: ignore | ||
| sa_column: Column | UndefinedType = Undefined, | ||
| sa_column_args: Sequence[Any] | UndefinedType = Undefined, | ||
| sa_column_kwargs: Mapping[str, Any] | UndefinedType = Undefined, | ||
| schema_extra: dict[str, Any] | None = None, | ||
|
|
@@ -525,17 +525,17 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): | |
| model_fields: ClassVar[dict[str, FieldInfo]] | ||
|
|
||
| # Replicate SQLAlchemy | ||
| def __setattr__(cls, name: str, value: Any) -> None: | ||
| def __setattr__(cls, key: str, value: Any) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__setattr__(cls, name, value) | ||
| DeclarativeMeta.__setattr__(cls, key, value) | ||
| else: | ||
| super().__setattr__(name, value) | ||
| super().__setattr__(key, value) | ||
|
|
||
| def __delattr__(cls, name: str) -> None: | ||
| def __delattr__(cls, key: str) -> None: | ||
| if is_table_model_class(cls): | ||
| DeclarativeMeta.__delattr__(cls, name) | ||
| DeclarativeMeta.__delattr__(cls, key) | ||
| else: | ||
| super().__delattr__(name) | ||
| super().__delattr__(key) | ||
|
Comment on lines
-528
to
+538
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| # From Pydantic | ||
| def __new__( | ||
|
|
@@ -649,7 +649,7 @@ def __init__( | |
| # Plain forward references, for models not yet defined, are not | ||
| # handled well by SQLAlchemy without Mapped, so, wrap the | ||
| # annotations in Mapped here | ||
| cls.__annotations__[rel_name] = Mapped[ann] # type: ignore[valid-type] | ||
| cls.__annotations__[rel_name] = Mapped[ann] | ||
| relationship_to = get_relationship_to( | ||
| name=rel_name, rel_info=rel_info, annotation=ann | ||
| ) | ||
|
|
@@ -738,7 +738,7 @@ def get_sqlalchemy_type(field: Any) -> Any: | |
| raise ValueError(f"{type_} has no matching SQLAlchemy type") | ||
|
|
||
|
|
||
| def get_column_from_field(field: Any) -> Column: # type: ignore | ||
| def get_column_from_field(field: Any) -> Column: | ||
| field_info = field | ||
| sa_column = _get_sqlmodel_field_value(field_info, "sa_column", Undefined) | ||
| if isinstance(sa_column, Column): | ||
|
|
@@ -773,7 +773,7 @@ def get_column_from_field(field: Any) -> Column: # type: ignore | |
| assert isinstance(foreign_key, str) | ||
| assert isinstance(ondelete_value, (str, type(None))) # for typing | ||
| args.append(ForeignKey(foreign_key, ondelete=ondelete_value)) | ||
| kwargs = { | ||
| kwargs: dict[str, Any] = { | ||
| "primary_key": primary_key, | ||
| "nullable": nullable, | ||
| "index": index, | ||
|
|
@@ -797,7 +797,7 @@ def get_column_from_field(field: Any) -> Column: # type: ignore | |
| return Column(sa_type, *args, **kwargs) | ||
|
|
||
|
|
||
| class_registry = weakref.WeakValueDictionary() # type: ignore | ||
| class_registry = weakref.WeakValueDictionary() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we even need this |
||
|
|
||
| default_registry = registry() | ||
|
|
||
|
|
@@ -850,7 +850,7 @@ def __setattr__(self, name: str, value: Any) -> None: | |
| return | ||
| else: | ||
| # Set in SQLAlchemy, before Pydantic to trigger events and updates | ||
| if is_table_model_class(self.__class__) and is_instrumented(self, name): # type: ignore[no-untyped-call] | ||
| if is_table_model_class(self.__class__) and is_instrumented(self, name): | ||
| set_attribute(self, name, value) | ||
| # Set in Pydantic model to trigger possible validation changes, only for | ||
| # non relationship values | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,13 @@ def where(self, *whereclause: _ColumnExpressionArgument[bool] | bool) -> Self: | |
| """Return a new `Select` construct with the given expression added to | ||
| its `WHERE` clause, joined to the existing clause via `AND`, if any. | ||
| """ | ||
| return super().where(*whereclause) # type: ignore[arg-type] | ||
| return super().where(*whereclause) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's |
||
|
|
||
| def having(self, *having: _ColumnExpressionArgument[bool] | bool) -> Self: | ||
| """Return a new `Select` construct with the given expression added to | ||
| its `HAVING` clause, joined to the existing clause via `AND`, if any. | ||
| """ | ||
| return super().having(*having) # type: ignore[arg-type] | ||
| return super().having(*having) | ||
|
|
||
|
|
||
| class Select(SelectBase[_T]): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tycomplaints with:So basically we can't have
__varif there is a scalar parameter in front of this one.As a quick fix, I changed all double underscores to singles, but it feels a bit like a hack. We could also suppress the
tywarning, but that also feels wrong...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just renaming it to single-underscored would be incorrect.
As I understand, double-underscored parameter names was a convention for position-only parameters before
, /syntax was added in 3.8.I suggest we update this to use names without leading underscores, and update template to add
, /to each signature ofselect:Alternatively we can leave
__entand renameentity_..parameters to__entity_..