Skip to content

Commit c26569f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 507053e commit c26569f

3 files changed

Lines changed: 31 additions & 15 deletions

File tree

‎returns/maybe.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ def __replace__(self, **changes: Any) -> '_Nothing':
354354
anything other than ``None`` raises a TypeError.
355355
"""
356356
if '_inner_value' in changes and changes['_inner_value'] is not None:
357-
raise TypeError('Cannot replace _inner_value on Nothing with a non-None value')
357+
raise TypeError(
358+
'Cannot replace _inner_value on Nothing with a non-None value'
359+
)
358360
if 'inner_value' in changes and changes['inner_value'] is not None:
359-
raise TypeError('Cannot replace inner_value on Nothing with a non-None value')
361+
raise TypeError(
362+
'Cannot replace inner_value on Nothing with a non-None value'
363+
)
360364
changes.pop('_inner_value', None)
361365
changes.pop('inner_value', None)
362366
if changes:

‎returns/primitives/container.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC
2-
from typing import Any, TypeVar
2+
from typing import Any, Self, TypeVar
33

44
from typing_extensions import TypedDict
55

@@ -69,7 +69,7 @@ def __setstate__(self, state: _PickleState | Any) -> None:
6969
# backward compatibility with 0.19.0 and earlier
7070
object.__setattr__(self, '_inner_value', state)
7171

72-
def __replace__(self: _ContainerType, **changes: Any) -> _ContainerType:
72+
def __replace__(self, **changes: Any) -> Self:
7373
"""
7474
Implements Python 3.13 ``copy.replace`` protocol.
7575

‎tests/test_primitives/test_container/test_base_container/test_replace.py‎

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from typing import Any
44

55
import pytest
6-
from hypothesis import example, given
6+
from hypothesis import given
77
from hypothesis import strategies as st
88

99
from returns.io import IO
10-
from returns.maybe import Maybe, Nothing, Some
10+
from returns.maybe import Nothing, Some
1111
from returns.primitives.container import BaseContainer
12-
from returns.result import Failure, Result, Success
12+
from returns.result import Failure, Success
1313

1414

1515
@given(st.integers(), st.integers())
@@ -25,7 +25,9 @@ def test_base_container_replace_inner_value(initial: int, new_val: int):
2525

2626

2727
@given(st.text(), st.text())
28-
def test_base_container_replace_underscore_inner_value(initial: str, new_val: str):
28+
def test_base_container_replace_underscore_inner_value(
29+
initial: str, new_val: str
30+
):
2931
"""Ensures that __replace__ accepts _inner_value keyword argument."""
3032
container = BaseContainer(initial)
3133
replaced = container.__replace__(_inner_value=new_val)
@@ -46,14 +48,16 @@ def test_base_container_replace_no_args():
4648
def test_base_container_replace_unexpected_kwarg():
4749
"""Ensures that unexpected kwargs raise TypeError."""
4850
container = BaseContainer(42)
49-
with pytest.raises(TypeError, match="unexpected keyword argument 'invalid'"):
51+
with pytest.raises(
52+
TypeError, match="unexpected keyword argument 'invalid'"
53+
):
5054
container.__replace__(invalid=True)
5155

5256

5357
def test_base_container_replace_multiple_values():
5458
"""Ensures providing both inner_value and _inner_value raises TypeError."""
5559
container = BaseContainer(42)
56-
with pytest.raises(TypeError, match="multiple values for inner value"):
60+
with pytest.raises(TypeError, match='multiple values for inner value'):
5761
container.__replace__(inner_value=1, _inner_value=2)
5862

5963

@@ -66,7 +70,9 @@ def test_base_container_replace_multiple_values():
6670
(IO(100), 200, IO(200)),
6771
],
6872
)
69-
def test_concrete_containers_replace(container: Any, new_value: Any, expected: Any):
73+
def test_concrete_containers_replace(
74+
container: Any, new_value: Any, expected: Any
75+
):
7076
"""Ensures concrete containers support __replace__."""
7177
replaced = container.__replace__(inner_value=new_value)
7278
assert replaced == expected
@@ -79,17 +85,23 @@ def test_nothing_replace():
7985
assert Nothing.__replace__(inner_value=None) is Nothing
8086
assert Nothing.__replace__(_inner_value=None) is Nothing
8187

82-
with pytest.raises(TypeError, match="Cannot replace inner_value on Nothing"):
88+
with pytest.raises(
89+
TypeError, match='Cannot replace inner_value on Nothing'
90+
):
8391
Nothing.__replace__(inner_value=42)
8492

85-
with pytest.raises(TypeError, match="Cannot replace _inner_value on Nothing"):
93+
with pytest.raises(
94+
TypeError, match='Cannot replace _inner_value on Nothing'
95+
):
8696
Nothing.__replace__(_inner_value=42)
8797

8898

89-
@pytest.mark.skipif(sys.version_info < (3, 13), reason="copy.replace was added in Python 3.13")
99+
@pytest.mark.skipif(
100+
sys.version_info < (3, 13), reason='copy.replace was added in Python 3.13'
101+
)
90102
def test_copy_replace_standard_library():
91103
"""Ensures stdlib copy.replace works seamlessly on Python 3.13+."""
92-
replace = getattr(copy, "replace")
104+
replace = copy.replace
93105
s = Success(1)
94106
replaced = replace(s, inner_value=2)
95107
assert replaced == Success(2)

0 commit comments

Comments
 (0)