diff --git a/pydantic/class_validators.py b/pydantic/class_validators.py index a93d570eae..b6a26dab39 100644 --- a/pydantic/class_validators.py +++ b/pydantic/class_validators.py @@ -54,7 +54,7 @@ def validator( check_fields: bool = True, whole: bool = None, allow_reuse: bool = False, -) -> Callable[[AnyCallable], classmethod]: +) -> Callable[[AnyCallable], classmethod]: # type: ignore[type-arg] """ Decorate methods on the class indicating that they should be used to validate fields :param fields: which field(s) the method should be called on @@ -81,7 +81,7 @@ def validator( assert each_item is False, '"each_item" and "whole" conflict, remove "whole"' each_item = not whole - def dec(f: AnyCallable) -> classmethod: + def dec(f: AnyCallable) -> classmethod: # type: ignore[type-arg] f_cls = _prepare_validator(f, allow_reuse) setattr( f_cls, @@ -97,20 +97,20 @@ def dec(f: AnyCallable) -> classmethod: @overload -def root_validator(_func: AnyCallable) -> classmethod: +def root_validator(_func: AnyCallable) -> classmethod: # type: ignore[type-arg] ... @overload def root_validator( *, pre: bool = False, allow_reuse: bool = False, skip_on_failure: bool = False -) -> Callable[[AnyCallable], classmethod]: +) -> Callable[[AnyCallable], classmethod]: # type: ignore[type-arg] ... def root_validator( _func: Optional[AnyCallable] = None, *, pre: bool = False, allow_reuse: bool = False, skip_on_failure: bool = False -) -> Union[classmethod, Callable[[AnyCallable], classmethod]]: +) -> Union[classmethod, Callable[[AnyCallable], classmethod]]: # type: ignore[type-arg] """ Decorate methods on a model indicating that they should be used to validate (and perhaps modify) data either before or after standard model parsing/validation is performed. @@ -122,7 +122,7 @@ def root_validator( ) return f_cls - def dec(f: AnyCallable) -> classmethod: + def dec(f: AnyCallable) -> classmethod: # type: ignore[type-arg] f_cls = _prepare_validator(f, allow_reuse) setattr( f_cls, ROOT_VALIDATOR_CONFIG_KEY, Validator(func=f_cls.__func__, pre=pre, skip_on_failure=skip_on_failure) @@ -132,7 +132,7 @@ def dec(f: AnyCallable) -> classmethod: return dec -def _prepare_validator(function: AnyCallable, allow_reuse: bool) -> classmethod: +def _prepare_validator(function: AnyCallable, allow_reuse: bool) -> classmethod: # type: ignore[type-arg] """ Avoid validators with duplicated names since without this, validators can be overwritten silently which generally isn't the intended behaviour, don't run in ipython (see #312) or if allow_reuse is False. @@ -325,7 +325,7 @@ def _generic_validator_basic(validator: AnyCallable, sig: 'Signature', args: Set return lambda cls, v, values, field, config: validator(v, values=values, field=field, config=config) -def gather_all_validators(type_: 'ModelOrDc') -> Dict[str, classmethod]: +def gather_all_validators(type_: 'ModelOrDc') -> Dict[str, classmethod]: # type: ignore[type-arg] all_attributes = ChainMap(*[cls.__dict__ for cls in type_.__mro__]) return { k: v diff --git a/pydantic/main.py b/pydantic/main.py index a00cc0a3e1..ab5fb42a4b 100644 --- a/pydantic/main.py +++ b/pydantic/main.py @@ -890,7 +890,7 @@ def create_model( __config__: Optional[Type[BaseConfig]] = None, __base__: None = None, __module__: str = __name__, - __validators__: Dict[str, classmethod] = None, + __validators__: Dict[str, classmethod] = None, # type: ignore[type-arg] **field_definitions: Any, ) -> Type['BaseModel']: ... @@ -903,7 +903,7 @@ def create_model( __config__: Optional[Type[BaseConfig]] = None, __base__: Union[Type['Model'], Tuple[Type['Model'], ...]], __module__: str = __name__, - __validators__: Dict[str, classmethod] = None, + __validators__: Dict[str, classmethod] = None, # type: ignore[type-arg] **field_definitions: Any, ) -> Type['Model']: ... @@ -915,7 +915,7 @@ def create_model( __config__: Optional[Type[BaseConfig]] = None, __base__: Union[None, Type['Model'], Tuple[Type['Model'], ...]] = None, __module__: str = __name__, - __validators__: Dict[str, classmethod] = None, + __validators__: Dict[str, classmethod] = None, # type: ignore[type-arg] **field_definitions: Any, ) -> Type['Model']: """ diff --git a/pydantic/mypy.py b/pydantic/mypy.py index d8ad93db1c..e7b7996a77 100644 --- a/pydantic/mypy.py +++ b/pydantic/mypy.py @@ -348,13 +348,13 @@ def add_construct_method(self, fields: List['PydanticModelField']) -> None: and does not treat settings fields as optional. """ ctx = self._ctx - set_str = ctx.api.named_type('__builtins__.set', [ctx.api.named_type('__builtins__.str')]) + set_str = ctx.api.named_type('builtins.set', [ctx.api.named_type('builtins.str')]) optional_set_str = UnionType([set_str, NoneType()]) fields_set_argument = Argument(Var('_fields_set', optional_set_str), optional_set_str, None, ARG_OPT) construct_arguments = self.get_field_arguments(fields, typed=True, force_all_optional=False, use_alias=False) construct_arguments = [fields_set_argument] + construct_arguments - obj_type = ctx.api.named_type('__builtins__.object') + obj_type = ctx.api.named_type('builtins.object') self_tvar_name = '_PydanticBaseModel' # Make sure it does not conflict with other names in the class tvar_fullname = ctx.cls.fullname + '.' + self_tvar_name self_type = TypeVarType(self_tvar_name, tvar_fullname, -1, [], obj_type) @@ -654,7 +654,7 @@ def add_method( arg_names.append(get_name(arg.variable)) arg_kinds.append(arg.kind) - function_type = ctx.api.named_type('__builtins__.function') + function_type = ctx.api.named_type('builtins.function') signature = CallableType(arg_types, arg_kinds, arg_names, return_type, function_type) if tvar_like_type: signature.variables = [tvar_like_type] diff --git a/pydantic/utils.py b/pydantic/utils.py index f0a594c888..31ff5dc644 100644 --- a/pydantic/utils.py +++ b/pydantic/utils.py @@ -574,7 +574,7 @@ def _coerce_items(items: Union['AbstractSetIntStr', 'MappingIntStrAny']) -> 'Map elif isinstance(items, AbstractSet): items = dict.fromkeys(items, ...) else: - raise TypeError(f'Unexpected type of exclude value {items.__class__}') + raise TypeError(f'Unexpected type of exclude value {items.__class__}') # type: ignore[attr-defined] return items @classmethod diff --git a/tests/mypy/outputs/plugin-fail-strict.txt b/tests/mypy/outputs/plugin-fail-strict.txt index 6606daf05b..6dbaff7cda 100644 --- a/tests/mypy/outputs/plugin-fail-strict.txt +++ b/tests/mypy/outputs/plugin-fail-strict.txt @@ -33,7 +33,7 @@ 186: error: Unexpected keyword argument "z" for "AliasGeneratorModel2" [call-arg] 189: error: Name "Missing" is not defined [name-defined] 197: error: No overload variant of "dataclass" matches argument type "Dict[, ]" [call-overload] -197: note: Possible overload variant: +197: note: Possible overload variants: 197: note: def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ...) -> Callable[[Type[Any]], Type[Dataclass]] -197: note: <1 more non-matching overload not shown> +197: note: def dataclass(_cls: Type[Any], *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ...) -> Type[Dataclass] 219: error: Property "y" defined in "FrozenModel" is read-only [misc] \ No newline at end of file diff --git a/tests/mypy/outputs/plugin-fail.txt b/tests/mypy/outputs/plugin-fail.txt index 1619a4e242..3176bc2dce 100644 --- a/tests/mypy/outputs/plugin-fail.txt +++ b/tests/mypy/outputs/plugin-fail.txt @@ -18,11 +18,11 @@ 101: error: Missing named argument "y" for "construct" of "Model" [call-arg] 103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type] 156: error: Missing named argument "x" for "DynamicAliasModel2" [call-arg] -175: error: unused "type: ignore" comment -182: error: unused "type: ignore" comment +175: error: Unused "type: ignore" comment +182: error: Unused "type: ignore" comment 189: error: Name "Missing" is not defined [name-defined] 197: error: No overload variant of "dataclass" matches argument type "Dict[, ]" [call-overload] -197: note: Possible overload variant: +197: note: Possible overload variants: 197: note: def dataclass(*, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ...) -> Callable[[Type[Any]], Type[Dataclass]] -197: note: <1 more non-matching overload not shown> +197: note: def dataclass(_cls: Type[Any], *, init: bool = ..., repr: bool = ..., eq: bool = ..., order: bool = ..., unsafe_hash: bool = ..., frozen: bool = ..., config: Optional[Type[Any]] = ...) -> Type[Dataclass] 219: error: Property "y" defined in "FrozenModel" is read-only [misc] \ No newline at end of file diff --git a/tests/requirements-linting.txt b/tests/requirements-linting.txt index 259fa76799..263524bc27 100644 --- a/tests/requirements-linting.txt +++ b/tests/requirements-linting.txt @@ -3,7 +3,7 @@ flake8==4.0.1 flake8-quotes==3.3.1 hypothesis==6.31.6 isort==5.10.1 -mypy==0.920 +mypy==0.930 pre-commit==2.16.0 pycodestyle==2.8.0 pyflakes==2.4.0 diff --git a/tests/requirements-testing.txt b/tests/requirements-testing.txt index 892dba137d..1ee135251b 100644 --- a/tests/requirements-testing.txt +++ b/tests/requirements-testing.txt @@ -2,7 +2,7 @@ coverage==6.2 hypothesis==6.31.6 # pin importlib-metadata as upper versions need typing-extensions to work if on python < 3.8 importlib-metadata==3.1.0;python_version<"3.8" -mypy==0.920 +mypy==0.930 pytest==6.2.5 pytest-cov==3.0.0 pytest-mock==3.6.1