MCPcopy
hub / github.com/pydantic/pydantic / adjust_validator_signatures

Method adjust_validator_signatures

pydantic/v1/mypy.py:326–342  ·  view source on GitHub ↗

When we decorate a function `f` with `pydantic.validator(...), mypy sees `f` as a regular method taking a `self` instance, even though pydantic internally wraps `f` with `classmethod` if necessary. Teach mypy this by marking any function whose outermost decorator is a

(self)

Source from the content-addressed store, hash-verified

324 }
325
326 def adjust_validator_signatures(self) -> None:
327 """When we decorate a function `f` with `pydantic.validator(...), mypy sees
328 `f` as a regular method taking a `self` instance, even though pydantic
329 internally wraps `f` with `classmethod` if necessary.
330
331 Teach mypy this by marking any function whose outermost decorator is a
332 `validator()` call as a classmethod.
333 """
334 for name, sym in self._ctx.cls.info.names.items():
335 if isinstance(sym.node, Decorator):
336 first_dec = sym.node.original_decorators[0]
337 if (
338 isinstance(first_dec, CallExpr)
339 and isinstance(first_dec.callee, NameExpr)
340 and first_dec.callee.fullname == f'{_NAMESPACE}.class_validators.validator'
341 ):
342 sym.node.func.is_class = True
343
344 def collect_config(self) -> 'ModelConfigData':
345 """

Callers 1

transformMethod · 0.95

Calls 1

itemsMethod · 0.45

Tested by

no test coverage detected