mirror of
				https://github.com/fastapi/sqlmodel.git
				synced 2025-11-04 06:37:29 +08:00 
			
		
		
		
	⬆ Upgrade mypy, fix type annotations (#218)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							7fcd4fd7c5
						
					
				
				
					commit
					8d1b6f079a
				
			@ -37,7 +37,7 @@ sqlalchemy2-stubs = {version = "*", allow-prereleases = true}
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
[tool.poetry.dev-dependencies]
 | 
					[tool.poetry.dev-dependencies]
 | 
				
			||||||
pytest = "^6.2.4"
 | 
					pytest = "^6.2.4"
 | 
				
			||||||
mypy = "^0.910"
 | 
					mypy = "0.930"
 | 
				
			||||||
flake8 = "^3.9.2"
 | 
					flake8 = "^3.9.2"
 | 
				
			||||||
black = {version = "^21.5-beta.1", python = "^3.7"}
 | 
					black = {version = "^21.5-beta.1", python = "^3.7"}
 | 
				
			||||||
mkdocs = "^1.2.1"
 | 
					mkdocs = "^1.2.1"
 | 
				
			||||||
 | 
				
			|||||||
@ -6,7 +6,6 @@ from decimal import Decimal
 | 
				
			|||||||
from enum import Enum
 | 
					from enum import Enum
 | 
				
			||||||
from pathlib import Path
 | 
					from pathlib import Path
 | 
				
			||||||
from typing import (
 | 
					from typing import (
 | 
				
			||||||
    TYPE_CHECKING,
 | 
					 | 
				
			||||||
    AbstractSet,
 | 
					    AbstractSet,
 | 
				
			||||||
    Any,
 | 
					    Any,
 | 
				
			||||||
    Callable,
 | 
					    Callable,
 | 
				
			||||||
@ -24,11 +23,11 @@ from typing import (
 | 
				
			|||||||
    cast,
 | 
					    cast,
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pydantic import BaseModel
 | 
					from pydantic import BaseConfig, BaseModel
 | 
				
			||||||
from pydantic.errors import ConfigError, DictError
 | 
					from pydantic.errors import ConfigError, DictError
 | 
				
			||||||
from pydantic.fields import FieldInfo as PydanticFieldInfo
 | 
					from pydantic.fields import FieldInfo as PydanticFieldInfo
 | 
				
			||||||
from pydantic.fields import ModelField, Undefined, UndefinedType
 | 
					from pydantic.fields import ModelField, Undefined, UndefinedType
 | 
				
			||||||
from pydantic.main import BaseConfig, ModelMetaclass, validate_model
 | 
					from pydantic.main import ModelMetaclass, validate_model
 | 
				
			||||||
from pydantic.typing import ForwardRef, NoArgAnyCallable, resolve_annotations
 | 
					from pydantic.typing import ForwardRef, NoArgAnyCallable, resolve_annotations
 | 
				
			||||||
from pydantic.utils import ROOT_KEY, Representation
 | 
					from pydantic.utils import ROOT_KEY, Representation
 | 
				
			||||||
from sqlalchemy import (
 | 
					from sqlalchemy import (
 | 
				
			||||||
@ -453,7 +452,7 @@ def get_column_from_field(field: ModelField) -> Column:  # type: ignore
 | 
				
			|||||||
    sa_column_kwargs = getattr(field.field_info, "sa_column_kwargs", Undefined)
 | 
					    sa_column_kwargs = getattr(field.field_info, "sa_column_kwargs", Undefined)
 | 
				
			||||||
    if sa_column_kwargs is not Undefined:
 | 
					    if sa_column_kwargs is not Undefined:
 | 
				
			||||||
        kwargs.update(cast(Dict[Any, Any], sa_column_kwargs))
 | 
					        kwargs.update(cast(Dict[Any, Any], sa_column_kwargs))
 | 
				
			||||||
    return Column(sa_type, *args, **kwargs)
 | 
					    return Column(sa_type, *args, **kwargs)  # type: ignore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class_registry = weakref.WeakValueDictionary()  # type: ignore
 | 
					class_registry = weakref.WeakValueDictionary()  # type: ignore
 | 
				
			||||||
@ -494,9 +493,6 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
 | 
				
			|||||||
    def __init__(__pydantic_self__, **data: Any) -> None:
 | 
					    def __init__(__pydantic_self__, **data: Any) -> None:
 | 
				
			||||||
        # Uses something other than `self` the first arg to allow "self" as a
 | 
					        # Uses something other than `self` the first arg to allow "self" as a
 | 
				
			||||||
        # settable attribute
 | 
					        # settable attribute
 | 
				
			||||||
        if TYPE_CHECKING:
 | 
					 | 
				
			||||||
            __pydantic_self__.__dict__: Dict[str, Any] = {}
 | 
					 | 
				
			||||||
            __pydantic_self__.__fields_set__: Set[str] = set()
 | 
					 | 
				
			||||||
        values, fields_set, validation_error = validate_model(
 | 
					        values, fields_set, validation_error = validate_model(
 | 
				
			||||||
            __pydantic_self__.__class__, data
 | 
					            __pydantic_self__.__class__, data
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
@ -608,7 +604,7 @@ class SQLModel(BaseModel, metaclass=SQLModelMetaclass, registry=default_registry
 | 
				
			|||||||
            return cls(**value_as_dict)
 | 
					            return cls(**value_as_dict)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # From Pydantic, override to only show keys from fields, omit SQLAlchemy attributes
 | 
					    # From Pydantic, override to only show keys from fields, omit SQLAlchemy attributes
 | 
				
			||||||
    def _calculate_keys(  # type: ignore
 | 
					    def _calculate_keys(
 | 
				
			||||||
        self,
 | 
					        self,
 | 
				
			||||||
        include: Optional[Mapping[Union[int, str], Any]],
 | 
					        include: Optional[Mapping[Union[int, str], Any]],
 | 
				
			||||||
        exclude: Optional[Mapping[Union[int, str], Any]],
 | 
					        exclude: Optional[Mapping[Union[int, str], Any]],
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user