Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wrapt instead of functools.wraps in order to preserve function si… #198

Closed
wants to merge 1 commit into from

Conversation

jwelch92
Copy link

@jwelch92 jwelch92 commented Dec 6, 2021

…gnatures.

Which problem is this PR solving?

Short description of the changes

  • Changes existing decorators that use only functools.wraps to use the wrapt.decorator decorator instead. This allows beeline traced functions to keep their original signature intact.

@MikeGoldsmith MikeGoldsmith added type: bug Something isn't working version: bump minor A PR that adds behavior, but is backwards-compatible. labels Dec 8, 2021
@MikeGoldsmith MikeGoldsmith self-assigned this Dec 8, 2021
@JamieDanielson
Copy link
Contributor

@jwelch92 this is looking good so far. I notice it's a draft but figured I'd take a look and provide some feedback. The linting is breaking in the CI build - can you take a look? Also, in testing the update with the same scenario you provided in the issue, I am seeing the same result. These two things may be related, let us know what you think!

CI Linting error:

#!/bin/bash -eo pipefail
poetry run pylint --rcfile=pylint.rc beeline
************* Module beeline.aiotrace
beeline/aiotrace.py:81:19: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/aiotrace.py:81:19: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/aiotrace.py:81:19: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
beeline/aiotrace.py:88:19: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/aiotrace.py:88:19: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/aiotrace.py:88:19: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
beeline/aiotrace.py:94:19: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/aiotrace.py:94:19: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/aiotrace.py:94:19: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
beeline/aiotrace.py:123:15: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/aiotrace.py:123:15: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/aiotrace.py:123:15: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
beeline/aiotrace.py:139:15: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/aiotrace.py:139:15: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/aiotrace.py:139:15: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
************* Module beeline.trace
beeline/trace.py:421:19: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/trace.py:421:19: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/trace.py:421:19: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)
beeline/trace.py:427:19: E1120: No value for argument 'instance' in function call (no-value-for-parameter)
beeline/trace.py:427:19: E1120: No value for argument 'args' in function call (no-value-for-parameter)
beeline/trace.py:427:19: E1120: No value for argument 'kwargs' in function call (no-value-for-parameter)

Exited with code exit status 2
CircleCI received exit code 2

Result using updated wrapt instead of functools.wrap in local testing:

Example function: example_traced
Full Arg Spec: FullArgSpec(args=[], varargs='args', varkw='kwargs', defaults=None, kwonlyargs=[], kwonlydefaults=None, annotations={'return': None})
Signature: (a: str, b: str, c: Optional[str] = None) -> None

@JamieDanielson JamieDanielson self-assigned this Dec 8, 2021
@JamieDanielson JamieDanielson added the status: revision needed Waiting for response to changes requested. label Dec 9, 2021
@jwelch92
Copy link
Author

Thanks for taking a look @JamieDanielson! I'll try to address this feedback when I get a chance.

Are there any guidelines or rules for when it is appropriate to supress linting rules? Based on wrapt's docs I think no matter what there will be a function with some unused arguments in order to have a compatible signature for what wrapt expects.

Thanks!

@vreynolds vreynolds added status: revision needed Waiting for response to changes requested. and removed status: revision needed Waiting for response to changes requested. labels Dec 14, 2021
@vreynolds
Copy link
Contributor

vreynolds commented Dec 14, 2021

Hey @jwelch92,

As far as the linter errors, I believe they are trying to tell us that the callers of those functions supply a different number of arguments from what's defined in the signature (not that those arguments are unused inside the function definition). That does appear to be the case, though I am unsure if that's intentional or not -- there's like several layers of higher order functions in there 😅 I assume this is the same issue described here

I think if it is intentional, and the decorators are meant to change the function signature, we can use signature-mutators in the Pylint config, or just suppress those warnings inline.

@vreynolds vreynolds removed their assignment Dec 29, 2021
@github-actions
Copy link

Marking this PR as stale because it has been open 30 days with no activity. Please add a comment if this PR is still relevant; otherwise this PR will be automatically closed in 7 days.

@github-actions github-actions bot added the Stale label Jan 29, 2022
@github-actions
Copy link

github-actions bot commented Feb 6, 2022

Closing this PR due to inactivity. Please see our Honeycomb OSS Lifecyle and Practices.

@github-actions github-actions bot closed this Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale status: revision needed Waiting for response to changes requested. type: bug Something isn't working version: bump minor A PR that adds behavior, but is backwards-compatible.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beeline tracing decorator does preserve function signature
4 participants