-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-self-cached type hint caching x 2.
This commit is the next in a commit chain internally caching **non-self-cached type hints** (i.e., hints that do *not* internally cache themselves somewhere like PEP 563- or 585-compliant type hints) and coercing semantically equal non-self-cached type hints into syntactically equal `@beartype`-cached type hints, dramatically improving both the space and time efficiency of such hints. Specifically, this commit defines a new private `beartype._util.hint.pep.utilhintpeptest.is_hint_pep_uncached` tester returning ``True`` only if the passed PEP-compliant type hint is non-self-cached. Naturally, nothing is tested. Weep! (*Clouded endowment!*)
- Loading branch information
Showing
10 changed files
with
409 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env python3 | ||
# --------------------( LICENSE )-------------------- | ||
# Copyright (c) 2014-2021 Cecil Curry. | ||
# See "LICENSE" for further details. | ||
|
||
''' | ||
**Beartype callable getter utilities.** | ||
This private submodule implements utility functions dynamically introspecting | ||
high-level metadata attached to arbitrary callables. | ||
This private submodule is *not* intended for importation by downstream callers. | ||
''' | ||
|
||
# ....................{ IMPORTS }.................... | ||
from beartype.roar import _BeartypeUtilCallableException | ||
from collections.abc import Callable | ||
|
||
# ....................{ GETTERS }.................... | ||
#FIXME: Unit test us up. | ||
def get_func_wrappee(func: Callable) -> Callable: | ||
''' | ||
**Wrappee** (i.e., lower-level callable) originally wrapped by the passed | ||
**wrapper** (i.e., higher-level callable typically produced by the | ||
:mod:`functools.wraps` decorator) if this wrapper actually is a wrapper | ||
*or* raise an exception otherwise (i.e., if this wrapper is *not* actually | ||
a wrapper). | ||
Parameters | ||
---------- | ||
func : Callable | ||
Wrapper to be unwrapped. | ||
Returns | ||
---------- | ||
Callable | ||
Wrappee wrapped by this wrapper. | ||
Raises | ||
---------- | ||
_BeartypeUtilCallableException | ||
If this callable is *not* a wrapper. | ||
''' | ||
assert callable(func), f'{repr(func)} not callable.' | ||
|
||
# Wrappee wrapped by this wrapper if this wrapper actually is a wrapper | ||
# *OR* "None" otherwise. | ||
wrappee = getattr(func, '__wrapped__', None) | ||
|
||
# If this wrapper is *NOT* actually a wrapper, raise an exception. | ||
if wrappee is None: | ||
raise _BeartypeUtilCallableException( | ||
f'Callable {func} not wrapper ' | ||
f'(i.e., "__wrapped__" attribute undefined).') | ||
# Else, this wrapper is a wrapper. In this case, this wrappee exists. | ||
|
||
# Return this wrappee. | ||
return wrappee |
Oops, something went wrong.