Skip to content

Commit 3c2eefe

Browse files
committed
ignore cache for pep585
1 parent 609858f commit 3c2eefe

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Lib/functools.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,13 @@ def dispatch(cls_obj):
902902
if cache_token != current_token:
903903
dispatch_cache.clear()
904904
cache_token = current_token
905-
try:
906-
impl = dispatch_cache[cls]
907-
except KeyError:
905+
906+
907+
# if PEP-585 types are not registered for the given *cls*,
908+
# then we can use the cache. Otherwise, the cache cannot be used
909+
# because we need to confirm every item matches first
910+
from typing import get_origin
911+
if not any(i for i in registry.keys() if get_origin(i) == cls):
908912
try:
909913
impl = registry[cls]
910914
except KeyError:

0 commit comments

Comments
 (0)