Skip to content

Commit 8ef492b

Browse files
authored
build(deps): bump mypy from 0.920 to 0.930 (#3573)
* build(deps): bump mypy from 0.920 to 0.930 * fix: avoid mypy plugin crash Due to python/mypy#11332, mypy would crash because `__builtins__` is not part of `ctx.api` modules, `builtins` is * fix tests
1 parent 2d3d266 commit 8ef492b

8 files changed

+23
-23
lines changed

pydantic/class_validators.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def validator(
5454
check_fields: bool = True,
5555
whole: bool = None,
5656
allow_reuse: bool = False,
57-
) -> Callable[[AnyCallable], classmethod]:
57+
) -> Callable[[AnyCallable], classmethod]: # type: ignore[type-arg]
5858
"""
5959
Decorate methods on the class indicating that they should be used to validate fields
6060
:param fields: which field(s) the method should be called on
@@ -81,7 +81,7 @@ def validator(
8181
assert each_item is False, '"each_item" and "whole" conflict, remove "whole"'
8282
each_item = not whole
8383

84-
def dec(f: AnyCallable) -> classmethod:
84+
def dec(f: AnyCallable) -> classmethod: # type: ignore[type-arg]
8585
f_cls = _prepare_validator(f, allow_reuse)
8686
setattr(
8787
f_cls,
@@ -97,20 +97,20 @@ def dec(f: AnyCallable) -> classmethod:
9797

9898

9999
@overload
100-
def root_validator(_func: AnyCallable) -> classmethod:
100+
def root_validator(_func: AnyCallable) -> classmethod: # type: ignore[type-arg]
101101
...
102102

103103

104104
@overload
105105
def root_validator(
106106
*, pre: bool = False, allow_reuse: bool = False, skip_on_failure: bool = False
107-
) -> Callable[[AnyCallable], classmethod]:
107+
) -> Callable[[AnyCallable], classmethod]: # type: ignore[type-arg]
108108
...
109109

110110

111111
def root_validator(
112112
_func: Optional[AnyCallable] = None, *, pre: bool = False, allow_reuse: bool = False, skip_on_failure: bool = False
113-
) -> Union[classmethod, Callable[[AnyCallable], classmethod]]:
113+
) -> Union[classmethod, Callable[[AnyCallable], classmethod]]: # type: ignore[type-arg]
114114
"""
115115
Decorate methods on a model indicating that they should be used to validate (and perhaps modify) data either
116116
before or after standard model parsing/validation is performed.
@@ -122,7 +122,7 @@ def root_validator(
122122
)
123123
return f_cls
124124

125-
def dec(f: AnyCallable) -> classmethod:
125+
def dec(f: AnyCallable) -> classmethod: # type: ignore[type-arg]
126126
f_cls = _prepare_validator(f, allow_reuse)
127127
setattr(
128128
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:
132132
return dec
133133

134134

135-
def _prepare_validator(function: AnyCallable, allow_reuse: bool) -> classmethod:
135+
def _prepare_validator(function: AnyCallable, allow_reuse: bool) -> classmethod: # type: ignore[type-arg]
136136
"""
137137
Avoid validators with duplicated names since without this, validators can be overwritten silently
138138
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
325325
return lambda cls, v, values, field, config: validator(v, values=values, field=field, config=config)
326326

327327

328-
def gather_all_validators(type_: 'ModelOrDc') -> Dict[str, classmethod]:
328+
def gather_all_validators(type_: 'ModelOrDc') -> Dict[str, classmethod]: # type: ignore[type-arg]
329329
all_attributes = ChainMap(*[cls.__dict__ for cls in type_.__mro__])
330330
return {
331331
k: v

pydantic/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def create_model(
890890
__config__: Optional[Type[BaseConfig]] = None,
891891
__base__: None = None,
892892
__module__: str = __name__,
893-
__validators__: Dict[str, classmethod] = None,
893+
__validators__: Dict[str, classmethod] = None, # type: ignore[type-arg]
894894
**field_definitions: Any,
895895
) -> Type['BaseModel']:
896896
...
@@ -903,7 +903,7 @@ def create_model(
903903
__config__: Optional[Type[BaseConfig]] = None,
904904
__base__: Union[Type['Model'], Tuple[Type['Model'], ...]],
905905
__module__: str = __name__,
906-
__validators__: Dict[str, classmethod] = None,
906+
__validators__: Dict[str, classmethod] = None, # type: ignore[type-arg]
907907
**field_definitions: Any,
908908
) -> Type['Model']:
909909
...
@@ -915,7 +915,7 @@ def create_model(
915915
__config__: Optional[Type[BaseConfig]] = None,
916916
__base__: Union[None, Type['Model'], Tuple[Type['Model'], ...]] = None,
917917
__module__: str = __name__,
918-
__validators__: Dict[str, classmethod] = None,
918+
__validators__: Dict[str, classmethod] = None, # type: ignore[type-arg]
919919
**field_definitions: Any,
920920
) -> Type['Model']:
921921
"""

pydantic/mypy.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -348,13 +348,13 @@ def add_construct_method(self, fields: List['PydanticModelField']) -> None:
348348
and does not treat settings fields as optional.
349349
"""
350350
ctx = self._ctx
351-
set_str = ctx.api.named_type('__builtins__.set', [ctx.api.named_type('__builtins__.str')])
351+
set_str = ctx.api.named_type('builtins.set', [ctx.api.named_type('builtins.str')])
352352
optional_set_str = UnionType([set_str, NoneType()])
353353
fields_set_argument = Argument(Var('_fields_set', optional_set_str), optional_set_str, None, ARG_OPT)
354354
construct_arguments = self.get_field_arguments(fields, typed=True, force_all_optional=False, use_alias=False)
355355
construct_arguments = [fields_set_argument] + construct_arguments
356356

357-
obj_type = ctx.api.named_type('__builtins__.object')
357+
obj_type = ctx.api.named_type('builtins.object')
358358
self_tvar_name = '_PydanticBaseModel' # Make sure it does not conflict with other names in the class
359359
tvar_fullname = ctx.cls.fullname + '.' + self_tvar_name
360360
self_type = TypeVarType(self_tvar_name, tvar_fullname, -1, [], obj_type)
@@ -654,7 +654,7 @@ def add_method(
654654
arg_names.append(get_name(arg.variable))
655655
arg_kinds.append(arg.kind)
656656

657-
function_type = ctx.api.named_type('__builtins__.function')
657+
function_type = ctx.api.named_type('builtins.function')
658658
signature = CallableType(arg_types, arg_kinds, arg_names, return_type, function_type)
659659
if tvar_like_type:
660660
signature.variables = [tvar_like_type]

pydantic/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def _coerce_items(items: Union['AbstractSetIntStr', 'MappingIntStrAny']) -> 'Map
574574
elif isinstance(items, AbstractSet):
575575
items = dict.fromkeys(items, ...)
576576
else:
577-
raise TypeError(f'Unexpected type of exclude value {items.__class__}')
577+
raise TypeError(f'Unexpected type of exclude value {items.__class__}') # type: ignore[attr-defined]
578578
return items
579579

580580
@classmethod

tests/mypy/outputs/plugin-fail-strict.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
186: error: Unexpected keyword argument "z" for "AliasGeneratorModel2" [call-arg]
3434
189: error: Name "Missing" is not defined [name-defined]
3535
197: error: No overload variant of "dataclass" matches argument type "Dict[<nothing>, <nothing>]" [call-overload]
36-
197: note: Possible overload variant:
36+
197: note: Possible overload variants:
3737
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]]
38-
197: note: <1 more non-matching overload not shown>
38+
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]
3939
219: error: Property "y" defined in "FrozenModel" is read-only [misc]

tests/mypy/outputs/plugin-fail.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
101: error: Missing named argument "y" for "construct" of "Model" [call-arg]
1919
103: error: Argument "x" to "construct" of "Model" has incompatible type "str"; expected "int" [arg-type]
2020
156: error: Missing named argument "x" for "DynamicAliasModel2" [call-arg]
21-
175: error: unused "type: ignore" comment
22-
182: error: unused "type: ignore" comment
21+
175: error: Unused "type: ignore" comment
22+
182: error: Unused "type: ignore" comment
2323
189: error: Name "Missing" is not defined [name-defined]
2424
197: error: No overload variant of "dataclass" matches argument type "Dict[<nothing>, <nothing>]" [call-overload]
25-
197: note: Possible overload variant:
25+
197: note: Possible overload variants:
2626
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]]
27-
197: note: <1 more non-matching overload not shown>
27+
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]
2828
219: error: Property "y" defined in "FrozenModel" is read-only [misc]

tests/requirements-linting.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ flake8==4.0.1
33
flake8-quotes==3.3.1
44
hypothesis==6.31.6
55
isort==5.10.1
6-
mypy==0.920
6+
mypy==0.930
77
pre-commit==2.16.0
88
pycodestyle==2.8.0
99
pyflakes==2.4.0

tests/requirements-testing.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ coverage==6.2
22
hypothesis==6.31.6
33
# pin importlib-metadata as upper versions need typing-extensions to work if on python < 3.8
44
importlib-metadata==3.1.0;python_version<"3.8"
5-
mypy==0.920
5+
mypy==0.930
66
pytest==6.2.5
77
pytest-cov==3.0.0
88
pytest-mock==3.6.1

0 commit comments

Comments
 (0)