Skip to content

Commit

Permalink
Cleanup the typing module
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed May 11, 2024
1 parent b88889e commit 6e2f861
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 322 deletions.
2 changes: 1 addition & 1 deletion Lib/test/libregrtest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def clear_caches():
except KeyError:
pass
else:
for f in typing._cleanups:
for f in typing._CACHE_CLEANUPS:
f()

try:
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Example:
class Forward: ...

def clear_typing_caches():
for f in typing._cleanups:
for f in typing._CACHE_CLEANUPS:
f()


Expand Down
16 changes: 8 additions & 8 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def assertNotIsSubclass(self, cls, class_or_tuple, msg=None):
raise self.failureException(message)

def clear_caches(self):
for f in typing._cleanups:
for f in typing._CACHE_CLEANUPS:
f()


Expand Down Expand Up @@ -6398,10 +6398,10 @@ def blah():

@cpython_only # gh-98713
def test_overload_on_compiled_functions(self):
with patch("typing._overload_registry",
with patch("typing._OVERLOAD_REGISTRY",
defaultdict(lambda: defaultdict(dict))):
# The registry starts out empty:
self.assertEqual(typing._overload_registry, {})
self.assertEqual(typing._OVERLOAD_REGISTRY, {})

# This should just not fail:
overload(sum)
Expand Down Expand Up @@ -6430,14 +6430,14 @@ def blah():
return blah, [overload1, overload2]

# Make sure we don't clear the global overload registry
@patch("typing._overload_registry",
@patch("typing._OVERLOAD_REGISTRY",
defaultdict(lambda: defaultdict(dict)))
def test_overload_registry(self):
# The registry starts out empty
self.assertEqual(typing._overload_registry, {})
self.assertEqual(typing._OVERLOAD_REGISTRY, {})

impl, overloads = self.set_up_overloads()
self.assertNotEqual(typing._overload_registry, {})
self.assertNotEqual(typing._OVERLOAD_REGISTRY, {})
self.assertEqual(list(get_overloads(impl)), overloads)

def some_other_func(): pass
Expand All @@ -6452,13 +6452,13 @@ def not_overloaded(): pass
# Make sure that after we clear all overloads, the registry is
# completely empty.
clear_overloads()
self.assertEqual(typing._overload_registry, {})
self.assertEqual(typing._OVERLOAD_REGISTRY, {})
self.assertEqual(get_overloads(impl), [])

# Querying a function with no overloads shouldn't change the registry.
def the_only_one(): pass
self.assertEqual(get_overloads(the_only_one), [])
self.assertEqual(typing._overload_registry, {})
self.assertEqual(typing._OVERLOAD_REGISTRY, {})

def test_overload_registry_repeated(self):
for _ in range(2):
Expand Down
Loading

0 comments on commit 6e2f861

Please sign in to comment.