Repository: HypothesisWorks/hypothesis

Issue:
TypeError on CPython 3.13 for 6.99.2
I got on CPython 3.13a4 (during collection of tests by pytest):
```
    /Library/Frameworks/Python.framework/Versions/3.13/lib/python3.13/site-packages/hypothesis/strategies/_internal/strategies.py:56: in <module>
        Ex = TypeVar("Ex", covariant=True, default=Any)
    E   TypeError: typevar() got an unexpected keyword argument 'default'
```
CI logs: https://github.com/skirpichev/gmpy/actions/runs/8227832838/job/22496350932
deflake `test_can_generate_hard_values`
[Saw this fail again](https://github.com/HypothesisWorks/hypothesis/actions/runs/8230099344/job/22504897853) and figured I'd better pay up my IOU here. I think rejection sampling was the culprit of changing buffers here.


Discussion:

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py b/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py
--- a/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py
+++ b/hypothesis-python/src/hypothesis/strategies/_internal/strategies.py
@@ -52,12 +52,13 @@
 from hypothesis.strategies._internal.utils import defines_strategy
 from hypothesis.utils.conventions import UniqueIdentifier
 
-if sys.version_info >= (3, 13):
+# TODO: Use `(3, 13)` once Python 3.13 is released.
+if sys.version_info >= (3, 13, 0, "final"):
     Ex = TypeVar("Ex", covariant=True, default=Any)
 elif TYPE_CHECKING:
     from typing_extensions import TypeVar  # type: ignore[assignment]
 
-    Ex = TypeVar("Ex", covariant=True, default=Any)
+    Ex = TypeVar("Ex", covariant=True, default=Any)  # type: ignore[call-arg,misc]
 else:
     Ex = TypeVar("Ex", covariant=True)
 


Test patch:
diff --git a/hypothesis-python/tests/conjecture/test_data_tree.py b/hypothesis-python/tests/conjecture/test_data_tree.py
--- a/hypothesis-python/tests/conjecture/test_data_tree.py
+++ b/hypothesis-python/tests/conjecture/test_data_tree.py
@@ -519,16 +519,13 @@ def buf(data):
         data.draw_integer(min_value, max_value)
         data.freeze()
 
-    @run_to_buffer
-    def expected_buf(data):
-        data.draw_integer(min_value, max_value, forced=max_value)
-        data.mark_interesting()
-
     # this test doubles as conjecture coverage for using our child cache, so
     # ensure we don't miss that logic by getting lucky and drawing the correct
     # value once or twice.
     for _ in range(20):
-        assert tree.generate_novel_prefix(Random()) == expected_buf
+        prefix = tree.generate_novel_prefix(Random())
+        data = ConjectureData.for_buffer(prefix)
+        assert data.draw_integer(min_value, max_value) == 1000
 
 
 def test_can_generate_hard_floats():
diff --git a/hypothesis-python/tests/cover/test_filter_rewriting.py b/hypothesis-python/tests/cover/test_filter_rewriting.py
--- a/hypothesis-python/tests/cover/test_filter_rewriting.py
+++ b/hypothesis-python/tests/cover/test_filter_rewriting.py
@@ -12,6 +12,7 @@
 import math
 import operator
 import re
+import sys
 from fractions import Fraction
 from functools import partial
 from sys import float_info
@@ -34,6 +35,10 @@
 
 A_FEW = 15  # speed up massively-parametrized tests
 
+# FIXME-3.13: something about get_lambda_source not working with pytest-xdist?
+if sys.version_info[:2] == (3, 13) and sys.version_info.releaselevel < "final":
+    pytest.skip(allow_module_level=True)
+
 
 @pytest.mark.parametrize(
     "strategy, predicate, start, end",
diff --git a/hypothesis-python/tests/cover/test_lambda_formatting.py b/hypothesis-python/tests/cover/test_lambda_formatting.py
--- a/hypothesis-python/tests/cover/test_lambda_formatting.py
+++ b/hypothesis-python/tests/cover/test_lambda_formatting.py
@@ -8,6 +8,10 @@
 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
 # obtain one at https://mozilla.org/MPL/2.0/.
 
+import sys
+
+import pytest
+
 from hypothesis.internal.reflection import get_pretty_function_description
 
 
@@ -15,6 +19,7 @@ def test_bracket_whitespace_is_striped():
     assert get_pretty_function_description(lambda x: (x + 1)) == "lambda x: (x + 1)"
 
 
+@pytest.mark.skipif(sys.version_info[:2] == (3, 13), reason="FIXME-3.13")
 def test_no_whitespace_before_colon_with_no_args():
     assert get_pretty_function_description(eval("lambda: None")) == "lambda: <unknown>"
 
@@ -58,6 +63,7 @@ def test_variable_names_are_not_pretty():
     assert get_pretty_function_description(t) == "lambda x: True"
 
 
+@pytest.mark.skipif(sys.version_info[:2] == (3, 13), reason="FIXME-3.13")
 def test_does_not_error_on_dynamically_defined_functions():
     x = eval("lambda t: 1")
     get_pretty_function_description(x)