-
-
Notifications
You must be signed in to change notification settings - Fork 815
👷 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
Open
svlandeg
wants to merge
10
commits into
fastapi:main
Choose a base branch
from
svlandeg:feat/ty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+148
−182
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0251f0f
add ty to lint, precommit, pyproject and uv lock
svlandeg a52380b
add type annotation to kwargs dict
svlandeg 3203f83
remove unnecessary type ignore statements
svlandeg 5d9dd59
🎨 Auto format
pre-commit-ci-lite[bot] 5c9b1d5
avoid using double underscore when any positional-or-keyword paramete…
svlandeg c1b0465
one more
svlandeg 732847d
remove mypy
svlandeg 2f8efa3
Merge branch 'main' into feat/ty
svlandeg dc8593b
use same names as upstream class
svlandeg 1dceaa7
fix generator
svlandeg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
|
||
|
|
||
| # 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() | ||
|
|
||
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...