Skip to content

Commit 00edd7a

Browse files
authored
Merge pull request #3667 from Zac-HD/ci-312
Run Python 3.12 beta in CI
2 parents 42b7595 + 1cdf6ce commit 00edd7a

File tree

10 files changed

+60
-22
lines changed

10 files changed

+60
-22
lines changed

.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ jobs:
4444
- check-py311-cover
4545
- check-py311-nocover
4646
- check-py311-niche
47-
# - check-py312-cover
48-
# - check-py312-nocover
49-
# - check-py312-niche
47+
- check-py312-cover
48+
- check-py312-nocover
49+
- check-py312-niche
5050
# - check-py313-cover
5151
- check-quality
5252
## Skip all the (inactive/old) Rust and Ruby tests pending fixes

hypothesis-python/RELEASE.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
RELEASE_TYPE: patch
2+
3+
We now test against Python 3.12 beta in CI, and this patch
4+
fixes some new deprecations.

hypothesis-python/src/hypothesis/strategies/_internal/core.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,11 @@ def from_type_guarded(thing):
11231123
if types.is_a_union(thing):
11241124
args = sorted(thing.__args__, key=types.type_sorting_key)
11251125
return one_of([_from_type(t, recurse_guard) for t in args])
1126+
# We also have a special case for TypeVars.
1127+
# They are represented as instances like `~T` when they come here.
1128+
# We need to work with their type instead.
1129+
if isinstance(thing, TypeVar) and type(thing) in types._global_type_lookup:
1130+
return as_strategy(types._global_type_lookup[type(thing)], thing)
11261131
if not types.is_a_type(thing):
11271132
if isinstance(thing, str):
11281133
# See https://github.com/HypothesisWorks/hypothesis/issues/3016
@@ -1190,11 +1195,6 @@ def from_type_guarded(thing):
11901195
mapping={k: v for k, v in anns.items() if k not in optional},
11911196
optional={k: v for k, v in anns.items() if k in optional},
11921197
)
1193-
# We also have a special case for TypeVars.
1194-
# They are represented as instances like `~T` when they come here.
1195-
# We need to work with their type instead.
1196-
if isinstance(thing, TypeVar) and type(thing) in types._global_type_lookup:
1197-
return as_strategy(types._global_type_lookup[type(thing)], thing)
11981198

11991199
# If there's no explicitly registered strategy, maybe a subtype of thing
12001200
# is registered - if so, we can resolve it to the subclass strategy.

hypothesis-python/src/hypothesis/strategies/_internal/types.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def from_typing_type(thing):
429429
# Except for sequences of integers, or unions which include integer!
430430
# See https://github.com/HypothesisWorks/hypothesis/issues/2257
431431
#
432-
# This block drops ByteString from the types that can be generated
432+
# This block drops bytes from the types that can be generated
433433
# if there is more than one allowed type, and the element type is
434434
# not either `int` or a Union with `int` as one of its elements.
435435
elem_type = (getattr(thing, "__args__", None) or ["not int"])[0]
@@ -450,7 +450,7 @@ def from_typing_type(thing):
450450
and thing.__forward_arg__ in vars(builtins)
451451
):
452452
return st.from_type(getattr(builtins, thing.__forward_arg__))
453-
# Before Python 3.9, we sometimes have e.g. ByteString from both the typing
453+
# Before Python 3.9, we sometimes have e.g. Sequence from both the typing
454454
# module, and collections.abc module. Discard any type which is not it's own
455455
# origin, where the origin is also in the mapping.
456456
for t in sorted(mapping, key=type_sorting_key):

hypothesis-python/tests/cover/test_lookup.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
t
4747
for t in types._global_type_lookup
4848
# We ignore TypeVar, because it is not a Generic type:
49-
if isinstance(t, types.typing_root_type) and t != typing.TypeVar
49+
if isinstance(t, types.typing_root_type)
50+
and t != typing.TypeVar
51+
and (sys.version_info[:2] <= (3, 11) or t != typing.ByteString)
5052
),
5153
key=str,
5254
)
@@ -110,7 +112,11 @@ def test_typing_Type_Union(ex):
110112
@given(data=st.data())
111113
def test_rare_types(data, typ):
112114
ex = data.draw(from_type(typ))
113-
assert isinstance(ex, typ)
115+
with warnings.catch_warnings():
116+
if sys.version_info[:2] >= (3, 12):
117+
warnings.simplefilter("ignore", DeprecationWarning)
118+
# ByteString is deprecated in Python 3.12
119+
assert isinstance(ex, typ)
114120

115121

116122
class Elem:
@@ -752,7 +758,7 @@ def test_inference_on_generic_collections_abc_aliases(typ, data):
752758
def test_bytestring_not_treated_as_generic_sequence(val):
753759
# Check that we don't fall into the specific problem from
754760
# https://github.com/HypothesisWorks/hypothesis/issues/2257
755-
assert not isinstance(val, typing.ByteString)
761+
assert not isinstance(val, bytes)
756762
# Check it hasn't happened again from some other non-generic sequence type.
757763
for x in val:
758764
assert isinstance(x, set)
@@ -764,7 +770,7 @@ def test_bytestring_not_treated_as_generic_sequence(val):
764770
def test_bytestring_is_valid_sequence_of_int_and_parent_classes(type_):
765771
find_any(
766772
st.from_type(typing.Sequence[type_]),
767-
lambda val: isinstance(val, typing.ByteString),
773+
lambda val: isinstance(val, bytes),
768774
)
769775

770776

hypothesis-python/tests/cover/test_type_lookup.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ def test_uninspectable_from_type():
211211

212212
def _check_instances(t):
213213
# See https://github.com/samuelcolvin/pydantic/discussions/2508
214-
return t.__module__ != "typing" and not t.__module__.startswith("pydantic")
214+
return (
215+
t.__module__ != "typing"
216+
and t.__name__ != "ByteString"
217+
and not t.__module__.startswith("pydantic")
218+
)
215219

216220

217221
@pytest.mark.parametrize(

hypothesis-python/tests/cover/test_type_lookup_forward_ref.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_bound_type_cheking_only_forward_ref():
134134
st.builds(typechecking_only_fun).example()
135135

136136

137-
def test_bound_type_cheking_only_forward_ref_wrong_type():
137+
def test_bound_type_checking_only_forward_ref_wrong_type():
138138
"""We should check ``ForwardRef`` parameter name correctly."""
139139
with utils.temp_registered(ForwardRef("WrongType"), st.just(1)):
140140
with pytest.raises(ResolutionFailed):

hypothesis-python/tests/datetime/test_dateutil_timezones.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,27 @@
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

1111
import datetime as dt
12+
import sys
13+
import warnings
1214

1315
import pytest
14-
from dateutil import tz, zoneinfo
1516

1617
from hypothesis import assume, given
1718
from hypothesis.errors import FailedHealthCheck, InvalidArgument
18-
from hypothesis.extra.dateutil import timezones
1919
from hypothesis.strategies import data, datetimes, just, sampled_from, times
2020
from hypothesis.strategies._internal.datetime import datetime_does_not_exist
2121

2222
from tests.common.debug import assert_all_examples, find_any, minimal
2323
from tests.common.utils import fails_with
2424

25+
with warnings.catch_warnings():
26+
if sys.version_info[:2] >= (3, 12):
27+
# Prior to https://github.com/dateutil/dateutil/pull/1285/
28+
warnings.simplefilter("ignore", DeprecationWarning)
29+
from dateutil import tz, zoneinfo
30+
31+
from hypothesis.extra.dateutil import timezones
32+
2533

2634
def test_utc_is_minimal():
2735
assert tz.UTC is minimal(timezones())

hypothesis-python/tests/datetime/test_pytz_timezones.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
# obtain one at https://mozilla.org/MPL/2.0/.
1010

1111
import datetime as dt
12+
import sys
13+
import warnings
1214

1315
import pytest
14-
import pytz
15-
from dateutil.tz import datetime_exists
1616

1717
from hypothesis import assume, given
1818
from hypothesis.errors import InvalidArgument
19-
from hypothesis.extra.pytz import timezones
2019
from hypothesis.strategies import data, datetimes, just, sampled_from, times
2120
from hypothesis.strategies._internal.datetime import datetime_does_not_exist
2221

@@ -27,6 +26,16 @@
2726
minimal,
2827
)
2928

29+
with warnings.catch_warnings():
30+
if sys.version_info[:2] >= (3, 12):
31+
# See https://github.com/stub42/pytz/issues/105 and
32+
# https://github.com/dateutil/dateutil/pull/1285/
33+
warnings.simplefilter("ignore", DeprecationWarning)
34+
import pytz
35+
from dateutil.tz import datetime_exists
36+
37+
from hypothesis.extra.pytz import timezones
38+
3039

3140
def test_utc_is_minimal():
3241
assert pytz.UTC is minimal(timezones())

hypothesis-python/tests/nocover/test_from_type_recipe.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
from hypothesis import given, strategies as st
1212
from hypothesis.strategies._internal.types import _global_type_lookup
1313

14-
TYPES = sorted((x for x in _global_type_lookup if x.__module__ != "typing"), key=str)
14+
TYPES = sorted(
15+
(
16+
x
17+
for x in _global_type_lookup
18+
if x.__module__ != "typing" and x.__name__ != "ByteString"
19+
),
20+
key=str,
21+
)
1522

1623

1724
def everything_except(excluded_types):

0 commit comments

Comments
 (0)