Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tin/py311 #973

Merged
merged 6 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions tests/test_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class C:
assert 1 == len(attr.fields(C))
assert_init_annotations(C, x=typing.List[int])

@pytest.mark.skipif(
sys.version_info[:2] < (3, 11),
reason="Incompatible behavior on older Pythons",
)
@pytest.mark.parametrize("slots", [True, False])
def test_auto_attribs(self, slots):
"""
Expand Down Expand Up @@ -149,7 +153,7 @@ class C:
x=typing.List[int],
y=int,
z=int,
foo=typing.Optional[typing.Any],
foo=typing.Any,
)

@pytest.mark.parametrize("slots", [True, False])
Expand Down Expand Up @@ -384,8 +388,9 @@ def noop():

assert attr.converters.optional(noop).__annotations__ == {}

@pytest.mark.xfail(
sys.version_info[:2] == (3, 6), reason="Does not work on 3.6."
@pytest.mark.skipif(
sys.version_info[:2] < (3, 11),
reason="Incompatible behavior on older Pythons",
)
@pytest.mark.parametrize("slots", [True, False])
def test_annotations_strings(self, slots):
Expand Down Expand Up @@ -417,7 +422,7 @@ class C:
x=typing.List[int],
y=int,
z=int,
foo=typing.Optional[typing.Any],
foo=typing.Any,
)

@pytest.mark.parametrize("slots", [True, False])
Expand Down
8 changes: 6 additions & 2 deletions tests/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,7 +2275,9 @@ class C:
def __getstate__(self):
return ("hi",)

assert None is getattr(C(), "__setstate__", None)
assert getattr(object, "__setstate__", None) is getattr(
C, "__setstate__", None
)
Comment on lines +2278 to +2280
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm this makes no sense to me…this would pass if both don't exist, and if both are the same thing. this doesn't seem like a good test to me :)

maybe have two asserts, depending on version?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But... that's what we want. If both don't exist, or both exist and are the same, the functionality is correct. Right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uh…i guess i'll take your word for it? it just seems like there's cases where it passes when it shouldn't 🤔

just merge the other shit in then ¯_(ツ)_/¯


@attr.s(slots=slots, auto_detect=True)
class C:
Expand All @@ -2291,7 +2293,9 @@ def __setstate__(self, state):
i.__setstate__(())

assert True is i.called
assert None is getattr(C(), "__getstate__", None)
assert getattr(object, "__getstate__", None) is getattr(
C, "__getstate__", None
)

@pytest.mark.skipif(PY310, reason="Pre-3.10 only.")
def test_match_args_pre_310(self):
Expand Down
20 changes: 12 additions & 8 deletions tests/test_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,10 +660,12 @@ def test_no_getstate_setstate_for_dict_classes(self):
As long as getstate_setstate is None, nothing is done to dict
classes.
"""
i = C1(1, 2)

assert None is getattr(i, "__getstate__", None)
assert None is getattr(i, "__setstate__", None)
assert getattr(object, "__getstate__", None) is getattr(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

C1, "__getstate__", None
)
assert getattr(object, "__setstate__", None) is getattr(
C1, "__setstate__", None
)

def test_no_getstate_setstate_if_option_false(self):
"""
Expand All @@ -674,10 +676,12 @@ def test_no_getstate_setstate_if_option_false(self):
class C:
x = attr.ib()

i = C(42)

assert None is getattr(i, "__getstate__", None)
assert None is getattr(i, "__setstate__", None)
assert getattr(object, "__getstate__", None) is getattr(
C, "__getstate__", None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

)
assert getattr(object, "__setstate__", None) is getattr(
C, "__setstate__", None
)

@pytest.mark.parametrize("cls", [C2(1), C2Slots(1)])
def test_getstate_set_state_force_true(self, cls):
Expand Down