Fix tests on 3.15#760
Conversation
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #760 +/- ##
==========================================
- Coverage 97.38% 97.21% -0.18%
==========================================
Files 3 3
Lines 7773 7797 +24
==========================================
+ Hits 7570 7580 +10
- Misses 203 217 +14
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
| self.assertIsInstance(self.sentinel_type.__doc__, str) | ||
|
|
||
| def test_constructor(self): | ||
| self.assertIs(self.sentinel_type, type(self.sentinel_type)()) |
There was a problem hiding this comment.
doesn't hold true on Python 3.15, and doesn't seem worth having a conditional test for
| from test import support | ||
| with support.swap_attr(builtins, "int", dict): | ||
| self.assertIs(evaluate_forward_ref(typing.ForwardRef("int")), dict) |
There was a problem hiding this comment.
uv builds of Python don't have the test module available so this test failed for me locally
There was a problem hiding this comment.
I just put Codex on fixing the same issue and it decided to do this instead:
@@ -9530,9 +9555,7 @@ class EvaluateForwardRefTests(BaseTestCase):
)
self.assertIs(evaluate_forward_ref(typing.ForwardRef("int"), globals={"int": str}), str)
import builtins
-
- from test import support
- with support.swap_attr(builtins, "int", dict):
+ with patch.object(builtins, "int", dict):
self.assertIs(evaluate_forward_ref(typing.ForwardRef("int")), dict)
def test_nested_strings(self):
Seems simpler?
There was a problem hiding this comment.
oh that's nice, i forgot about patch.object
There was a problem hiding this comment.
I made that change. I wonder what benefit there is to test.support.swap_attr in the CPython test suite over just using mock.patch.object...
| if repr is not None: | ||
| warnings.warn( | ||
| "The 'repr' parameter is deprecated " | ||
| "and will be removed in Python 3.15.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) |
There was a problem hiding this comment.
we added the repr back upstream so I removed the deprecation (python/cpython#149654). The deprecation only exists on main, not on the latest release of typing_extensions, so this doesn't warrant a changelog entry
| @skipUnless(TYPING_3_15_0, reason='Deprecated sentinel APIs are available before 3.15') | ||
| def test_sentinel_removed_deprecated_apis(self): | ||
| with self.assertRaises(TypeError): | ||
| class SentinelSubclass(Sentinel): | ||
| pass | ||
| with self.assertRaises(TypeError): | ||
| sentinel() | ||
| with self.assertRaises(TypeError): | ||
| Sentinel(name="my_sentinel") | ||
| with self.assertRaises(AttributeError): | ||
| sentinel('my_sentinel').foo = "bar" |
There was a problem hiding this comment.
these all cause DeprecationWarnings in the typing_extensions backports but raise exceptions upstream on CPython. The deprecation warnings on Python <=3.14 are tested in the previous test immediately above this
Fixes #759