| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 02da85c commit e30c7ef
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,7 +37,7 @@ sqlalchemy2-stubs = {version = "*", allow-prereleases = true} | |||
| 37 | 37 | ||
| 38 | 38 | [tool.poetry.dev-dependencies] | |
| 39 | 39 | pytest = "^6.2.4" | |
| 40 | - mypy = "^0.812" | ||
| 40 | + mypy = "^0.910" | ||
| 41 | 41 | flake8 = "^3.9.2" | |
| 42 | 42 | black = {version = "^21.5-beta.1", python = "^3.7"} | |
| 43 | 43 | mkdocs = "^1.2.1" | |
@@ -98,3 +98,7 @@ warn_return_any = true | |||
| 98 | 98 | implicit_reexport = false | |
| 99 | 99 | strict_equality = true | |
| 100 | 100 | # --strict end | |
| 101 | + | ||
| 102 | + [[tool.mypy.overrides]] | ||
| 103 | + module = "sqlmodel.sql.expression" | ||
| 104 | + warn_unused_ignores = false | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -136,4 +136,4 @@ def create_engine( | |||
| 136 | 136 | if not isinstance(query_cache_size, _DefaultPlaceholder): | |
| 137 | 137 | current_kwargs["query_cache_size"] = query_cache_size | |
| 138 | 138 | current_kwargs.update(kwargs) | |
| 139 | - return _create_engine(url, **current_kwargs) | ||
| 139 | + return _create_engine(url, **current_kwargs) # type: ignore | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ def __iter__(self) -> Iterator[_T]: | |||
| 23 | 23 | return super().__iter__() | |
| 24 | 24 | ||
| 25 | 25 | def __next__(self) -> _T: | |
| 26 | - return super().__next__() | ||
| 26 | + return super().__next__() # type: ignore | ||
| 27 | 27 | ||
| 28 | 28 | def first(self) -> Optional[_T]: | |
| 29 | 29 | return super().first() | |
@@ -32,7 +32,7 @@ def one_or_none(self) -> Optional[_T]: | |||
| 32 | 32 | return super().one_or_none() | |
| 33 | 33 | ||
| 34 | 34 | def one(self) -> _T: | |
| 35 | - return super().one() | ||
| 35 | + return super().one() # type: ignore | ||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | 38 | class Result(_Result, Generic[_T]): | |
@@ -70,10 +70,10 @@ def scalar_one(self) -> _T: | |||
| 70 | 70 | return super().scalar_one() # type: ignore | |
| 71 | 71 | ||
| 72 | 72 | def scalar_one_or_none(self) -> Optional[_T]: | |
| 73 | - return super().scalar_one_or_none() # type: ignore | ||
| 73 | + return super().scalar_one_or_none() | ||
| 74 | 74 | ||
| 75 | 75 | def one(self) -> _T: # type: ignore | |
| 76 | 76 | return super().one() # type: ignore | |
| 77 | 77 | ||
| 78 | 78 | def scalar(self) -> Optional[_T]: | |
| 79 | - return super().scalar() # type: ignore | ||
| 79 | + return super().scalar() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,7 +21,7 @@ def __init__( | |||
| 21 | 21 | self, | |
| 22 | 22 | bind: Optional[Union[AsyncConnection, AsyncEngine]] = None, | |
| 23 | 23 | binds: Optional[Mapping[object, Union[AsyncConnection, AsyncEngine]]] = None, | |
| 24 | - **kw, | ||
| 24 | + **kw: Any, | ||
| 25 | 25 | ): | |
| 26 | 26 | # All the same code of the original AsyncSession | |
| 27 | 27 | kw["future"] = True | |
@@ -52,7 +52,7 @@ async def exec( | |||
| 52 | 52 | # util.immutabledict has the union() method. Is this a bug in SQLAlchemy? | |
| 53 | 53 | execution_options = execution_options.union({"prebuffer_rows": True}) # type: ignore | |
| 54 | 54 | ||
| 55 | - return await greenlet_spawn( # type: ignore | ||
| 55 | + return await greenlet_spawn( | ||
| 56 | 56 | self.sync_session.exec, | |
| 57 | 57 | statement, | |
| 58 | 58 | params=params, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,7 +101,7 @@ def __init__( | |||
| 101 | 101 | *, | |
| 102 | 102 | back_populates: Optional[str] = None, | |
| 103 | 103 | link_model: Optional[Any] = None, | |
| 104 | - sa_relationship: Optional[RelationshipProperty] = None, | ||
| 104 | + sa_relationship: Optional[RelationshipProperty] = None, # type: ignore | ||
| 105 | 105 | sa_relationship_args: Optional[Sequence[Any]] = None, | |
| 106 | 106 | sa_relationship_kwargs: Optional[Mapping[str, Any]] = None, | |
| 107 | 107 | ) -> None: | |
@@ -127,32 +127,32 @@ def Field( | |||
| 127 | 127 | default: Any = Undefined, | |
| 128 | 128 | *, | |
| 129 | 129 | default_factory: Optional[NoArgAnyCallable] = None, | |
| 130 | - alias: str = None, | ||
| 131 | - title: str = None, | ||
| 132 | - description: str = None, | ||
| 130 | + alias: Optional[str] = None, | ||
| 131 | + title: Optional[str] = None, | ||
| 132 | + description: Optional[str] = None, | ||
| 133 | 133 | exclude: Union[ | |
| 134 | 134 | AbstractSet[Union[int, str]], Mapping[Union[int, str], Any], Any | |
| 135 | 135 | ] = None, | |
| 136 | 136 | include: Union[ | |
| 137 | 137 | AbstractSet[Union[int, str]], Mapping[Union[int, str], Any], Any | |
| 138 | 138 | ] = None, | |
| 139 | - const: bool = None, | ||
| 140 | - gt: float = None, | ||
| 141 | - ge: float = None, | ||
| 142 | - lt: float = None, | ||
| 143 | - le: float = None, | ||
| 144 | - multiple_of: float = None, | ||
| 145 | - min_items: int = None, | ||
| 146 | - max_items: int = None, | ||
| 147 | - min_length: int = None, | ||
| 148 | - max_length: int = None, | ||
| 139 | + const: Optional[bool] = None, | ||
| 140 | + gt: Optional[float] = None, | ||
| 141 | + ge: Optional[float] = None, | ||
| 142 | + lt: Optional[float] = None, | ||
| 143 | + le: Optional[float] = None, | ||
| 144 | + multiple_of: Optional[float] = None, | ||
| 145 | + min_items: Optional[int] = None, | ||
| 146 | + max_items: Optional[int] = None, | ||
| 147 | + min_length: Optional[int] = None, | ||
| 148 | + max_length: Optional[int] = None, | ||
| 149 | 149 | allow_mutation: bool = True, | |
| 150 | - regex: str = None, | ||
| 150 | + regex: Optional[str] = None, | ||
| 151 | 151 | primary_key: bool = False, | |
| 152 | 152 | foreign_key: Optional[Any] = None, | |
| 153 | 153 | nullable: Union[bool, UndefinedType] = Undefined, | |
| 154 | 154 | index: Union[bool, UndefinedType] = Undefined, | |
| 155 | - sa_column: Union[Column, UndefinedType] = Undefined, | ||
| 155 | + sa_column: Union[Column, UndefinedType] = Undefined, # type: ignore | ||
| 156 | 156 | sa_column_args: Union[Sequence[Any], UndefinedType] = Undefined, | |
| 157 | 157 | sa_column_kwargs: Union[Mapping[str, Any], UndefinedType] = Undefined, | |
| 158 | 158 | schema_extra: Optional[Dict[str, Any]] = None, | |
@@ -195,7 +195,7 @@ def Relationship( | |||
| 195 | 195 | *, | |
| 196 | 196 | back_populates: Optional[str] = None, | |
| 197 | 197 | link_model: Optional[Any] = None, | |
| 198 | - sa_relationship: Optional[RelationshipProperty] = None, | ||
| 198 | + sa_relationship: Optional[RelationshipProperty] = None, # type: ignore | ||
| 199 | 199 | sa_relationship_args: Optional[Sequence[Any]] = None, | |
| 200 | 200 | sa_relationship_kwargs: Optional[Mapping[str, Any]] = None, | |
| 201 | 201 | ) -> Any: | |
@@ -217,19 +217,25 @@ class SQLModelMetaclass(ModelMetaclass, DeclarativeMeta): | |||
| 217 | 217 | ||
| 218 | 218 | # Replicate SQLAlchemy | |
| 219 | 219 | def __setattr__(cls, name: str, value: Any) -> None: | |
| 220 | - if getattr(cls.__config__, "table", False): # type: ignore | ||
| 220 | + if getattr(cls.__config__, "table", False): | ||
| 221 | 221 | DeclarativeMeta.__setattr__(cls, name, value) | |
| 222 | 222 | else: | |
| 223 | 223 | super().__setattr__(name, value) | |
| 224 | 224 | ||
| 225 | 225 | def __delattr__(cls, name: str) -> None: | |
| 226 | - if getattr(cls.__config__, "table", False): # type: ignore | ||
| 226 | + if getattr(cls.__config__, "table", False): | ||
| 227 | 227 | DeclarativeMeta.__delattr__(cls, name) | |
| 228 | 228 | else: | |
| 229 | 229 | super().__delattr__(name) | |
| 230 | 230 | ||
| 231 | 231 | # From Pydantic | |
| 232 | - def __new__(cls, name, bases, class_dict: dict, **kwargs) -> Any: | ||
| 232 | + def __new__( | ||
| 233 | + cls, | ||
| 234 | + name: str, | ||
| 235 | + bases: Tuple[Type[Any], ...], | ||
| 236 | + class_dict: Dict[str, Any], | ||
| 237 | + **kwargs: Any, | ||
| 238 | + ) -> Any: | ||
| 233 | 239 | relationships: Dict[str, RelationshipInfo] = {} | |
| 234 | 240 | dict_for_pydantic = {} | |
| 235 | 241 | original_annotations = resolve_annotations( | |
@@ -342,7 +348,7 @@ def __init__( | |||
| 342 | 348 | ) | |
| 343 | 349 | relationship_to = temp_field.type_ | |
| 344 | 350 | if isinstance(temp_field.type_, ForwardRef): | |
| 345 | - relationship_to = temp_field.type_.__forward_arg__ # type: ignore | ||
| 351 | + relationship_to = temp_field.type_.__forward_arg__ | ||
| 346 | 352 | rel_kwargs: Dict[str, Any] = {} | |
| 347 | 353 | if rel_info.back_populates: | |
| 348 | 354 | rel_kwargs["back_populates"] = rel_info.back_populates | |
@@ -360,7 +366,7 @@ def __init__( | |||
| 360 | 366 | rel_args.extend(rel_info.sa_relationship_args) | |
| 361 | 367 | if rel_info.sa_relationship_kwargs: | |
| 362 | 368 | rel_kwargs.update(rel_info.sa_relationship_kwargs) | |
| 363 | - rel_value: RelationshipProperty = relationship( | ||
| 369 | + rel_value: RelationshipProperty = relationship( # type: ignore | ||
| 364 | 370 | relationship_to, *rel_args, **rel_kwargs | |
| 365 | 371 | ) | |
| 366 | 372 | dict_used[rel_name] = rel_value | |
@@ -408,7 +414,7 @@ def get_sqlachemy_type(field: ModelField) -> Any: | |||
| 408 | 414 | return GUID | |
| 409 | 415 | ||
| 410 | 416 | ||
| 411 | - def get_column_from_field(field: ModelField) -> Column: | ||
| 417 | + def get_column_from_field(field: ModelField) -> Column: # type: ignore | ||
| 412 | 418 | sa_column = getattr(field.field_info, "sa_column", Undefined) | |
| 413 | 419 | if isinstance(sa_column, Column): | |
| 414 | 420 | return sa_column | |
@@ -440,10 +446,10 @@ def get_column_from_field(field: ModelField) -> Column: | |||
| 440 | 446 | kwargs["default"] = sa_default | |
| 441 | 447 | sa_column_args = getattr(field.field_info, "sa_column_args", Undefined) | |
| 442 | 448 | if sa_column_args is not Undefined: | |
| 443 | - args.extend(list(cast(Sequence, sa_column_args))) | ||
| 449 | + args.extend(list(cast(Sequence[Any], sa_column_args))) | ||
| 444 | 450 | sa_column_kwargs = getattr(field.field_info, "sa_column_kwargs", Undefined) | |
| 445 | 451 | if sa_column_kwargs is not Undefined: | |
| 446 | - kwargs.update(cast(dict, sa_column_kwargs)) | ||
| 452 | + kwargs.update(cast(Dict[Any, Any], sa_column_kwargs)) | ||
| 447 | 453 | return Column(sa_type, *args, **kwargs) | |
| 448 | 454 | ||
| 449 | 455 | ||
@@ -452,24 +458,27 @@ def get_column_from_field(field: ModelField) -> Column: | |||
| 452 | 458 | default_registry = registry() | |
| 453 | 459 | ||
| 454 | 460 | ||
| 455 | - def _value_items_is_true(v) -> bool: | ||
| 461 | + def _value_items_is_true(v: Any) -> bool: | ||
| 456 | 462 | # Re-implement Pydantic's ValueItems.is_true() as it hasn't been released as of | |
| 457 | 463 | # the current latest, Pydantic 1.8.2 | |
| 458 | 464 | return v is True or v is ... | |
| 459 | 465 | ||
| 460 | 466 | ||
| 467 | + _TSQLModel = TypeVar("_TSQLModel", bound="SQLModel") | ||
| 468 | + | ||
| 469 | + | ||
| 461 | 470 | class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry): | |
| 462 | 471 | # SQLAlchemy needs to set weakref(s), Pydantic will set the other slots values | |
| 463 | 472 | __slots__ = ("__weakref__",) | |
| 464 | 473 | __tablename__: ClassVar[Union[str, Callable[..., str]]] | |
| 465 | - __sqlmodel_relationships__: ClassVar[Dict[str, RelationshipProperty]] | ||
| 474 | + __sqlmodel_relationships__: ClassVar[Dict[str, RelationshipProperty]] # type: ignore | ||
| 466 | 475 | __name__: ClassVar[str] | |
| 467 | 476 | metadata: ClassVar[MetaData] | |
| 468 | 477 | ||
| 469 | 478 | class Config: | |
| 470 | 479 | orm_mode = True | |
| 471 | 480 | ||
| 472 | - def __new__(cls, *args, **kwargs) -> Any: | ||
| 481 | + def __new__(cls, *args: Any, **kwargs: Any) -> Any: | ||
| 473 | 482 | new_object = super().__new__(cls) | |
| 474 | 483 | # SQLAlchemy doesn't call __init__ on the base class | |
| 475 | 484 | # Ref: https://docs.sqlalchemy.org/en/14/orm/constructors.html | |
@@ -520,7 +529,9 @@ def __setattr__(self, name: str, value: Any) -> None: | |||
| 520 | 529 | super().__setattr__(name, value) | |
| 521 | 530 | ||
| 522 | 531 | @classmethod | |
| 523 | - def from_orm(cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None): | ||
| 532 | + def from_orm( | ||
| 533 | + cls: Type[_TSQLModel], obj: Any, update: Optional[Dict[str, Any]] = None | ||
| 534 | + ) -> _TSQLModel: | ||
| 524 | 535 | # Duplicated from Pydantic | |
| 525 | 536 | if not cls.__config__.orm_mode: | |
| 526 | 537 | raise ConfigError( | |
@@ -533,7 +544,7 @@ def from_orm(cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None): | |||
| 533 | 544 | # End SQLModel support dict | |
| 534 | 545 | if not getattr(cls.__config__, "table", False): | |
| 535 | 546 | # If not table, normal Pydantic code | |
| 536 | - m = cls.__new__(cls) | ||
| 547 | + m: _TSQLModel = cls.__new__(cls) | ||
| 537 | 548 | else: | |
| 538 | 549 | # If table, create the new instance normally to make SQLAlchemy create | |
| 539 | 550 | # the _sa_instance_state attribute | |
@@ -554,7 +565,7 @@ def from_orm(cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None): | |||
| 554 | 565 | ||
| 555 | 566 | @classmethod | |
| 556 | 567 | def parse_obj( | |
| 557 | - cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None | ||
| 568 | + cls: Type["SQLModel"], obj: Any, update: Optional[Dict[str, Any]] = None | ||
| 558 | 569 | ) -> "SQLModel": | |
| 559 | 570 | obj = cls._enforce_dict_if_root(obj) | |
| 560 | 571 | # SQLModel, support update dict | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,7 +60,7 @@ def exec( | |||
| 60 | 60 | results = super().execute( | |
| 61 | 61 | statement, | |
| 62 | 62 | params=params, | |
| 63 | - execution_options=execution_options, # type: ignore | ||
| 63 | + execution_options=execution_options, | ||
| 64 | 64 | bind_arguments=bind_arguments, | |
| 65 | 65 | _parent_execute_state=_parent_execute_state, | |
| 66 | 66 | _add_event=_add_event, | |
@@ -74,7 +74,7 @@ def execute( | |||
| 74 | 74 | self, | |
| 75 | 75 | statement: _Executable, | |
| 76 | 76 | params: Optional[Union[Mapping[str, Any], Sequence[Mapping[str, Any]]]] = None, | |
| 77 | - execution_options: Mapping[str, Any] = util.EMPTY_DICT, | ||
| 77 | + execution_options: Optional[Mapping[str, Any]] = util.EMPTY_DICT, | ||
| 78 | 78 | bind_arguments: Optional[Mapping[str, Any]] = None, | |
| 79 | 79 | _parent_execute_state: Optional[Any] = None, | |
| 80 | 80 | _add_event: Optional[Any] = None, | |
@@ -101,7 +101,7 @@ def execute( | |||
| 101 | 101 | return super().execute( # type: ignore | |
| 102 | 102 | statement, | |
| 103 | 103 | params=params, | |
| 104 | - execution_options=execution_options, # type: ignore | ||
| 104 | + execution_options=execution_options, | ||
| 105 | 105 | bind_arguments=bind_arguments, | |
| 106 | 106 | _parent_execute_state=_parent_execute_state, | |
| 107 | 107 | _add_event=_add_event, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,4 @@ | |||
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | class Executable(_Executable, Generic[_T]): | |
| 9 | - def __init__(self, *args, **kwargs): | ||
| 10 | - self.__dict__["_exec_options"] = kwargs.pop("_exec_options", None) | ||
| 11 | - super(_Executable, self).__init__(*args, **kwargs) | ||
| 9 | + pass | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,10 +45,10 @@ class SelectOfScalar(_Select, Generic[_TSelect]): | |||
| 45 | 45 | class GenericSelectMeta(GenericMeta, _Select.__class__): # type: ignore | |
| 46 | 46 | pass | |
| 47 | 47 | ||
| 48 | - class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): # type: ignore | ||
| 48 | + class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): | ||
| 49 | 49 | pass | |
| 50 | 50 | ||
| 51 | - class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): # type: ignore | ||
| 51 | + class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): | ||
| 52 | 52 | pass | |
| 53 | 53 | ||
| 54 | 54 | # Cast them for editors to work correctly, from several tricks tried, this works | |
@@ -65,9 +65,9 @@ class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMet | |||
| 65 | 65 | ||
| 66 | 66 | _TScalar_0 = TypeVar( | |
| 67 | 67 | "_TScalar_0", | |
| 68 | - Column, | ||
| 69 | - Sequence, | ||
| 70 | - Mapping, | ||
| 68 | + Column, # type: ignore | ||
| 69 | + Sequence, # type: ignore | ||
| 70 | + Mapping, # type: ignore | ||
| 71 | 71 | UUID, | |
| 72 | 72 | datetime, | |
| 73 | 73 | float, | |
@@ -83,9 +83,9 @@ class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMet | |||
| 83 | 83 | ||
| 84 | 84 | _TScalar_1 = TypeVar( | |
| 85 | 85 | "_TScalar_1", | |
| 86 | - Column, | ||
| 87 | - Sequence, | ||
| 88 | - Mapping, | ||
| 86 | + Column, # type: ignore | ||
| 87 | + Sequence, # type: ignore | ||
| 88 | + Mapping, # type: ignore | ||
| 89 | 89 | UUID, | |
| 90 | 90 | datetime, | |
| 91 | 91 | float, | |
@@ -101,9 +101,9 @@ class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMet | |||
| 101 | 101 | ||
| 102 | 102 | _TScalar_2 = TypeVar( | |
| 103 | 103 | "_TScalar_2", | |
| 104 | - Column, | ||
| 105 | - Sequence, | ||
| 106 | - Mapping, | ||
| 104 | + Column, # type: ignore | ||
| 105 | + Sequence, # type: ignore | ||
| 106 | + Mapping, # type: ignore | ||
| 107 | 107 | UUID, | |
| 108 | 108 | datetime, | |
| 109 | 109 | float, | |
@@ -119,9 +119,9 @@ class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMet | |||
| 119 | 119 | ||
| 120 | 120 | _TScalar_3 = TypeVar( | |
| 121 | 121 | "_TScalar_3", | |
| 122 | - Column, | ||
| 123 | - Sequence, | ||
| 124 | - Mapping, | ||
| 122 | + Column, # type: ignore | ||
| 123 | + Sequence, # type: ignore | ||
| 124 | + Mapping, # type: ignore | ||
| 125 | 125 | UUID, | |
| 126 | 126 | datetime, | |
| 127 | 127 | float, | |
@@ -446,14 +446,14 @@ def select( # type: ignore | |||
| 446 | 446 | # Generated overloads end | |
| 447 | 447 | ||
| 448 | 448 | ||
| 449 | - def select(*entities: Any, **kw: Any) -> Union[Select, SelectOfScalar]: | ||
| 449 | + def select(*entities: Any, **kw: Any) -> Union[Select, SelectOfScalar]: # type: ignore | ||
| 450 | 450 | if len(entities) == 1: | |
| 451 | 451 | return SelectOfScalar._create(*entities, **kw) # type: ignore | |
| 452 | 452 | return Select._create(*entities, **kw) # type: ignore | |
| 453 | 453 | ||
| 454 | 454 | ||
| 455 | 455 | # TODO: add several @overload from Python types to SQLAlchemy equivalents | |
| 456 | - def col(column_expression: Any) -> ColumnClause: | ||
| 456 | + def col(column_expression: Any) -> ColumnClause: # type: ignore | ||
| 457 | 457 | if not isinstance(column_expression, (ColumnClause, Column, InstrumentedAttribute)): | |
| 458 | 458 | raise RuntimeError(f"Not a SQLAlchemy column: {column_expression}") | |
| 459 | 459 | return column_expression | |
| Back | FazBrowse Home | New Git URL |
0 commit comments