(
f: FType | None = None, pure: bool = True, private: bool = False, check_well_formed=True
)
| 51 | # appear as a decorator by itself or to have optional arguments |
| 52 | # like @R.function(pure=False) |
| 53 | def function( |
| 54 | f: FType | None = None, pure: bool = True, private: bool = False, check_well_formed=True |
| 55 | ) -> Function | FType: |
| 56 | # pylint: disable=unused-argument |
| 57 | # (pure and private aren't used here, but are used later in parsing) |
| 58 | |
| 59 | # need to inspect the stack first because is_defined_in_class expects the outer class |
| 60 | # to be in a particular position in the stack |
| 61 | orig_stack = inspect.stack() |
| 62 | |
| 63 | def decorator_wrapper(f): |
| 64 | if not inspect.isfunction(f): |
| 65 | raise TypeError(f"Expect a function, but got: {f}") |
| 66 | if utils.is_defined_in_class(orig_stack, f): |
| 67 | return f |
| 68 | return parse(f, utils.inspect_function_capture(f), check_well_formed=check_well_formed) |
| 69 | |
| 70 | if f is not None: |
| 71 | # if there are no optional args given, this will directly invoke the wrapper |
| 72 | return decorator_wrapper(f) |
| 73 | else: |
| 74 | # if there is a optional arg given, it returns the wrapper function |
| 75 | # as a new decorator and applies it |
| 76 | setattr(decorator_wrapper, "dispatch_token", "relax") |
| 77 | return decorator_wrapper |
| 78 | |
| 79 | |
| 80 | setattr(function, "dispatch_token", "relax") |
nothing calls this directly
no test coverage detected
searching dependent graphs…