Skip to content

Commit cad2406

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

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ WORKDIR /app
33
COPY . .
44
RUN pip install -e .
55
RUN pip install pytest
6-
CMD ["/bin/bash"]
6+
CMD ["/bin/bash"]

Test.patch

1 Byte
Binary file not shown.

commit.txt

1 Byte
Binary file not shown.

solution.patch

1 Byte
Binary file not shown.

tests/test_factory_validation_order.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
from attrs import define, field, validators
21
import pytest
32

3+
from attrs import define, field, validators
4+
5+
46
def test_default_factory_runs_after_required_validation():
57
def make_b():
68
return 10
79

810
@define
911
class Item:
1012
a: int = field(validator=validators.gt(0))
11-
b: int = field(default=None, factory=make_b,
12-
validator=validators.gt(0))
13+
b: int = field(
14+
default=None, factory=make_b, validator=validators.gt(0)
15+
)
1316

1417
obj = Item(5)
1518
assert obj.b == 10
@@ -24,8 +27,9 @@ def cross_validate(instance, attribute, value):
2427
@define
2528
class Item:
2629
a: int = field()
27-
b: int = field(default=None, factory=lambda: 5,
28-
validator=cross_validate)
30+
b: int = field(
31+
default=None, factory=lambda: 5, validator=cross_validate
32+
)
2933

3034
with pytest.raises(ValueError):
3135
Item(5)

0 commit comments

Comments
 (0)