MCPcopy Index your code
hub / github.com/python/mypy / _add_dunder_replace

Method _add_dunder_replace

mypy/plugins/dataclasses.py:401–414  ·  view source on GitHub ↗

Add a `__replace__` method to the class, which is used to replace attributes in the `copy` module.

(self, attributes: list[DataclassAttribute])

Source from the content-addressed store, hash-verified

399 return True
400
401 def _add_dunder_replace(self, attributes: list[DataclassAttribute]) -> None:
402 """Add a `__replace__` method to the class, which is used to replace attributes in the `copy` module."""
403 args = [
404 attr.to_argument(self._cls.info, of="replace")
405 for attr in attributes
406 if attr.is_in_init
407 ]
408 add_method_to_class(
409 self._api,
410 self._cls,
411 "__replace__",
412 args=args,
413 return_type=fill_typevars(self._cls.info),
414 )
415
416 def _add_internal_replace_method(self, attributes: list[DataclassAttribute]) -> None:
417 """

Callers 1

transformMethod · 0.95

Calls 3

add_method_to_classFunction · 0.90
fill_typevarsFunction · 0.90
to_argumentMethod · 0.80

Tested by

no test coverage detected