-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
71 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
import weakref | ||
from typing import Callable, MutableSet, TypeVar | ||
import typing as t | ||
|
||
from .misc import iter_wrapped | ||
|
||
|
||
__all__ = ["does_not_alter_signature", "forwards_arguments"] | ||
|
||
|
||
C = TypeVar("C", bound=Callable) | ||
C = t.TypeVar("C", bound=t.Callable) | ||
|
||
|
||
DOES_NOT_ALTER_SIGNATURE: MutableSet[Callable] = weakref.WeakSet() | ||
FORWARDS_ARGUMENTS: MutableSet[Callable] = weakref.WeakSet() | ||
MARKS = weakref.WeakKeyDictionary[t.Callable, t.MutableSet[t.Callable]]() | ||
|
||
|
||
def does_not_alter_signature(func: C) -> C: | ||
DOES_NOT_ALTER_SIGNATURE.add(func) | ||
MARKS.setdefault(func, set()).add(does_not_alter_signature) | ||
return func | ||
|
||
|
||
def forwards_arguments(func: C) -> C: | ||
FORWARDS_ARGUMENTS.add(func) | ||
MARKS.setdefault(func, set()).add(forwards_arguments) | ||
return func | ||
|
||
|
||
def has_mark(func: t.Callable, mark: t.Callable) -> bool: | ||
for func in iter_wrapped(func): | ||
if mark in MARKS.get(func, ()): | ||
return True | ||
|
||
return False |
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