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

Test failure (again) with Python 3.9.0a6 #2427

Closed
michel-slm opened this issue May 12, 2020 · 1 comment · Fixed by #2428
Closed

Test failure (again) with Python 3.9.0a6 #2427

michel-slm opened this issue May 12, 2020 · 1 comment · Fixed by #2428
Labels
internals Stuff that only Hypothesis devs should ever see interop how to play nicely with other packages

Comments

@michel-slm
Copy link
Contributor

A continuation of #2348 -- there are 3 type errors uncovered by 4 tests (excerpted below). I'm trying to read through the codebase but someone familiar with it can probably figure out what's causing this faster.

ref: https://docs.python.org/3.9/whatsnew/3.9.html

full bug report: https://bugzilla.redhat.com/show_bug.cgi?id=1830976

__________ test_specialised_collection_types[A_NamedTuple-tuple-int] ___________
[gw1] linux -- Python 3.9.0 /usr/bin/python3
Traceback (most recent call last):
  File "/builddir/build/BUILD/hypothesis-hypothesis-python-5.10.4/hypothesis-python/tests/cover/test_lookup.py", line 131, in test_specialised_collection_types
...
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/internal/conjecture/data.py", line 888, in draw
    return strategy.do_draw(self)
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/strategies.py", line 658, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/core.py", line 1241, in <lambda>
    lambda value: target(*value[0], **value[1])  # type: ignore
TypeError: __new__() missing 1 required positional argument: 'elem'
____________________ test_infers_args_for_namedtuple_builds ____________________
[gw1] linux -- Python 3.9.0 /usr/bin/python3
Traceback (most recent call last):
  File "/builddir/build/BUILD/hypothesis-hypothesis-python-5.10.4/hypothesis-python/tests/cover/test_lookup.py", line 453, in test_infers_args_for_namedtuple_builds
...
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/internal/conjecture/data.py", line 888, in draw
    return strategy.do_draw(self)
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/strategies.py", line 658, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/core.py", line 1241, in <lambda>
    lambda value: target(*value[0], **value[1])  # type: ignore
TypeError: __new__() missing 1 required positional argument: 'a'
_________________ test_infers_args_for_namedtuple_from_type ___________________
[gw1] linux -- Python 3.9.0 /usr/bin/python3
Traceback (most recent call last):
  File "/builddir/build/BUILD/hypothesis-hypothesis-python-5.10.4/hypothesis-python/tests/cover/test_lookup.py", line 458, in test_infers_args_for_namedtuple_from_type
...
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/internal/conjecture/data.py", line 888, in draw
    return strategy.do_draw(self)
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/strategies.py", line 658, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/core.py", line 1241, in <lambda>
    lambda value: target(*value[0], **value[1])  # type: ignore
TypeError: __new__() missing 1 required positional argument: 'a'
_____________ test_resolves_forward_references_outside_annotations _____________
[gw1] linux -- Python 3.9.0 /usr/bin/python3
Traceback (most recent call last):
  File "/builddir/build/BUILD/hypothesis-hypothesis-python-5.10.4/hypothesis-python/tests/cover/test_lookup_py36.py", line 31, in test_resolves_forward_references_outside_annotations
...
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/internal/conjecture/data.py", line 888, in draw
    return strategy.do_draw(self)
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/strategies.py", line 658, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "/builddir/build/BUILDROOT/python-hypothesis-5.10.4-1.fc33.x86_64/usr/lib/python3.9/site-packages/hypothesis/strategies/_internal/core.py", line 1241, in <lambda>
    lambda value: target(*value[0], **value[1])  # type: ignore
TypeError: __new__() missing 3 required positional arguments: 'val', 'l', and 'r'
@michel-slm
Copy link
Contributor Author

Likely related to this change somehow: __field_types removed in favor of annotations:
https://bugs.python.org/issue40182

... but hypothesis is still testing for it:
https://github.com/HypothesisWorks/hypothesis/blob/master/hypothesis-python/src/hypothesis/internal/compat.py#L95

michel-slm added a commit to michel-slm/hypothesis that referenced this issue May 12, 2020
In Python 3.9, NamedTuples no longer have a `_field_type` attribute;
it has been deprecated since Python 3.8 and the `__annotations__`
attribute has identical information:

```
>>> from typing import NamedTuple
>>> class MyNT(NamedTuple):
...     x: int
...     y: int = 1
...
...
>>> issubclass(P, tuple)
True
>>> issubclass(P, NamedTuple)
False
>>> hasattr(MyNT, "_fields")
True
>>> hasattr(MyNT, "_field_types")
True
>>> hasattr(MyNT, "__annotations__")
True
>>> MyNT._field_types
{'x': <class 'int'>, 'y': <class 'int'>}
>>> MyNT.__annotations__
{'x': <class 'int'>, 'y': <class 'int'>}
```

see https://bugs.python.org/issue40182

Testing for the existence of *either* `_field_types` or
`__annotations__` fixes the four failing tests on Python 3.9:

```
/builddir/build/BUILD/hypothesis-hypothesis-python-5.12.0/hypothesis-python
<mock-chroot> sh-5.0# PYTHONPATH=/builddir/build/BUILDROOT/python-hypothesis-5.12.0-1.fc33.x86_64/usr/lib/python3.9/site-packages pytest tests/cover/test_lookup.py::test_infers_args_f
or_namedtuple_builds
==================== test session starts ====================
platform linux -- Python 3.9.0a6, pytest-4.6.10, py-1.8.0, pluggy-0.13.0
rootdir: /builddir/build/BUILD/hypothesis-hypothesis-python-5.12.0, inifile: pytest.ini
plugins: hypothesis-5.12.0, xdist-1.32.0, forked-1.1.1
collected 1 item

tests/cover/test_lookup.py .                          [100%]

================= slowest 20 test durations =================
0.23s call     hypothesis-python/tests/cover/test_lookup.py::test_infers_args_for_namedtuple_builds
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_infers_args_for_namedtuple_builds

(0.00 durations hidden.  Use -vv to show these durations.)
================= 1 passed in 0.45 seconds ==================
<mock-chroot> sh-5.0# grep -rl test_infers_args_for_namedtuple_builds *
tests/cover/__pycache__/test_lookup.cpython-39-PYTEST.pyc
tests/cover/test_lookup.py
<mock-chroot> sh-5.0# PYTHONPATH=/builddir/build/BUILDROOT/python-hypothesis-5.12.0-1.fc33.x86_64/usr/lib/python3.9/site-packages pytest tests/cover/test_lookup.py::test_infers_args_for_namedtuple_from_type
==================== test session starts ====================
platform linux -- Python 3.9.0a6, pytest-4.6.10, py-1.8.0, pluggy-0.13.0
rootdir: /builddir/build/BUILD/hypothesis-hypothesis-python-5.12.0, inifile: pytest.ini
plugins: hypothesis-5.12.0, xdist-1.32.0, forked-1.1.1
collected 1 item

tests/cover/test_lookup.py .                          [100%]

================= slowest 20 test durations =================
0.20s call     hypothesis-python/tests/cover/test_lookup.py::test_infers_args_for_namedtuple_from_type
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_infers_args_for_namedtuple_from_type

(0.00 durations hidden.  Use -vv to show these durations.)
================= 1 passed in 0.42 seconds ==================
<mock-chroot> sh-5.0# grep -rl test_resolves_forward_references_outside_annotations *
tests/cover/test_lookup_py36.py
tests/cover/__pycache__/test_lookup_py36.cpython-39-PYTEST.pyc
<mock-chroot> sh-5.0# PYTHONPATH=/builddir/build/BUILDROOT/python-hypothesis-5.12.0-1.fc33.x86_64/usr/lib/python3.9/site-packages pytest tests/cover/test_lookup_py36.py::test_resolves
_forward_references_outside_annotations
==================== test session starts ====================
platform linux -- Python 3.9.0a6, pytest-4.6.10, py-1.8.0, pluggy-0.13.0
rootdir: /builddir/build/BUILD/hypothesis-hypothesis-python-5.12.0, inifile: pytest.ini
plugins: hypothesis-5.12.0, xdist-1.32.0, forked-1.1.1
collected 1 item

tests/cover/test_lookup_py36.py .                     [100%]

================= slowest 20 test durations =================
0.93s call     hypothesis-python/tests/cover/test_lookup_py36.py::test_resolves_forward_references_outside_annotations
0.01s setup    hypothesis-python/tests/cover/test_lookup_py36.py::test_resolves_forward_references_outside_annotations

(0.00 durations hidden.  Use -vv to show these durations.)
================= 1 passed in 0.95 seconds ==================
<mock-chroot> sh-5.0# PYTHONPATH=/builddir/build/BUILDROOT/python-hypothesis-5.12.0-1.fc33.x86_64/usr/lib/python3.9/site-packages pytest tests/cover/test_lookup.py::test_infers_args_for_namedtuple_from_type^C
<mock-chroot> sh-5.0# grep -rl test_specialised_collection_types *
tests/cover/__pycache__/test_lookup.cpython-39-PYTEST.pyc
tests/cover/test_lookup.py
<mock-chroot> sh-5.0# PYTHONPATH=/builddir/build/BUILDROOT/python-hypothesis-5.12.0-1.fc33.x86_64/usr/lib/python3.9/site-packages pytest tests/cover/test_lookup.py::test_specialised_collection_types
==================== test session starts ====================
platform linux -- Python 3.9.0a6, pytest-4.6.10, py-1.8.0, pluggy-0.13.0
rootdir: /builddir/build/BUILD/hypothesis-hypothesis-python-5.12.0, inifile: pytest.ini
plugins: hypothesis-5.12.0, xdist-1.32.0, forked-1.1.1
collected 14 items

tests/cover/test_lookup.py ..............             [100%]

================= slowest 20 test durations =================
0.44s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ12-coll_type12-int]
0.34s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ2-dict-int]
0.34s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ4-dict_values-int]
0.34s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ11-coll_type11-int]
0.31s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ3-dict_keys-int]
0.30s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ10-coll_type10-int]
0.28s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ0-set-int]
0.26s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ1-frozenset-int]
0.23s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ9-coll_type9-int]
0.21s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ7-tuple-int]
0.20s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ5-list-int]
0.19s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ8-coll_type8-int]
0.13s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[A_NamedTuple-tuple-int]
0.10s call     hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ6-tuple-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ2-dict-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ0-set-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[A_NamedTuple-tuple-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ10-coll_type10-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ11-coll_type11-int]
0.02s setup    hypothesis-python/tests/cover/test_lookup.py::test_specialised_collection_types[typ4-dict_values-int]
================= 14 passed in 4.11 seconds =================
```

This addresses issue HypothesisWorks#2427 .
@Zac-HD Zac-HD added internals Stuff that only Hypothesis devs should ever see interop how to play nicely with other packages labels May 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Stuff that only Hypothesis devs should ever see interop how to play nicely with other packages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants