Visitar URL original
bpo-42345: Fix three issues with typing.Literal parameters by uriyyo · Pull Request #23294 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update signature of _tp_cache function
  • Loading branch information
uriyyo committed Nov 16, 2020
commit 9d2187a907f6d3e023ca946dde59bf0a1ceafb20
6 changes: 3 additions & 3 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ def _flatten_literal_params(parameters):
_cleanups = []


def _tp_cache(typed=False):
def _tp_cache(func=None, /, *, typed=False):
"""Internal wrapper caching __getitem__ of generic types with a fallback to
original function for non-hashable arguments.
Comment thread
uriyyo marked this conversation as resolved.
"""
if callable(typed):
return _tp_cache()(typed)
if func is not None:
return _tp_cache(typed=typed)(func)
Comment thread
uriyyo marked this conversation as resolved.
Outdated

def decorator(func):
cached = functools.lru_cache(typed=typed)(func)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Fix ``typing.Literal`` equals method to ignore the order of arguments.
Patch provided by Yurii Karabas.
Fix issue related to ``typing.Literal`` caching by adding ``typed``
parameter to ``typing._tp_cache`` function. Patch provided by Yurii Karabas.