Skip to content

Commit 0b6586a

Browse files
authored
Converters: copy() returns Self (#644)
1 parent 0c36adc commit 0b6586a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

HISTORY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Our backwards-compatibility policy can be found [here](https://github.com/python
2828
([#519](https://github.com/python-attrs/cattrs/issues/519) [#588](https://github.com/python-attrs/cattrs/pull/588))
2929
- Generic PEP 695 type aliases are now supported.
3030
([#611](https://github.com/python-attrs/cattrs/issues/611) [#618](https://github.com/python-attrs/cattrs/pull/618))
31+
- {meth}`Converter.copy` and {meth}`BaseConverter.copy` are correctly annotated as returning `Self`.
32+
([#644](https://github.com/python-attrs/cattrs/pull/644))
3133
- Many preconf converters (_bson_, stdlib JSON, _cbor2_, _msgpack_, _msgspec_, _orjson_, _ujson_) skip unstructuring `int` and `str` enums,
3234
leaving them to the underlying libraries to handle with greater efficiency.
3335
([#598](https://github.com/python-attrs/cattrs/pull/598))

src/cattrs/converters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from attrs import Attribute, resolve_types
1515
from attrs import has as attrs_has
16+
from typing_extensions import Self
1617

1718
from ._compat import (
1819
ANIES,
@@ -981,7 +982,7 @@ def copy(
981982
unstruct_strat: UnstructureStrategy | None = None,
982983
prefer_attrib_converters: bool | None = None,
983984
detailed_validation: bool | None = None,
984-
) -> BaseConverter:
985+
) -> Self:
985986
"""Create a copy of the converter, keeping all existing custom hooks.
986987
987988
:param detailed_validation: Whether to use a slightly slower mode for detailed
@@ -1367,7 +1368,7 @@ def copy(
13671368
unstruct_collection_overrides: Mapping[type, UnstructureHook] | None = None,
13681369
prefer_attrib_converters: bool | None = None,
13691370
detailed_validation: bool | None = None,
1370-
) -> Converter:
1371+
) -> Self:
13711372
"""Create a copy of the converter, keeping all existing custom hooks.
13721373
13731374
:param detailed_validation: Whether to use a slightly slower mode for detailed

0 commit comments

Comments
 (0)