summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/metadata/_functools.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-16 20:49:42 (GMT)
committerGitHub <noreply@github.com>2021-12-16 20:49:42 (GMT)
commit04deaee4c8d313717f3ea8f6a4fd70286d510d6e (patch)
tree16af6d5242d248eb93107332099485783599fd4b /Lib/importlib/metadata/_functools.py
parent109d96602199a91e94eb14b8cb3720841f22ded7 (diff)
downloadcpython-04deaee4c8d313717f3ea8f6a4fd70286d510d6e.zip
cpython-04deaee4c8d313717f3ea8f6a4fd70286d510d6e.tar.gz
cpython-04deaee4c8d313717f3ea8f6a4fd70286d510d6e.tar.bz2
bpo-44893: Implement EntryPoint as simple class with attributes. (GH-30150)
* bpo-44893: Implement EntryPoint as simple class and deprecate tuple access in favor of attribute access. Syncs with importlib_metadata 4.8.1. * Apply refactorings found in importlib_metadata 4.8.2.
Diffstat (limited to 'Lib/importlib/metadata/_functools.py')
-rw-r--r--Lib/importlib/metadata/_functools.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/importlib/metadata/_functools.py b/Lib/importlib/metadata/_functools.py
index 73f50d0..71f66bd 100644
--- a/Lib/importlib/metadata/_functools.py
+++ b/Lib/importlib/metadata/_functools.py
@@ -83,3 +83,22 @@ def method_cache(method, cache_wrapper=None):
wrapper.cache_clear = lambda: None
return wrapper
+
+
+# From jaraco.functools 3.3
+def pass_none(func):
+ """
+ Wrap func so it's not called if its first param is None
+
+ >>> print_text = pass_none(print)
+ >>> print_text('text')
+ text
+ >>> print_text(None)
+ """
+
+ @functools.wraps(func)
+ def wrapper(param, *args, **kwargs):
+ if param is not None:
+ return func(param, *args, **kwargs)
+
+ return wrapper