Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update wrapt to 1.14.1 to avoid issues with ImportFinder on Pyth…
…on 3.10 (#3789) (#3812) Changelog: https://github.com/GrahamDumpleton/wrapt/blob/f2f1a680113d500f525de78da91ae19235efef16/docs/changes.rst Updating to address issue with new Python requiring find_spec for import hooks ## Reproduction Running the Starlette test suite with Python 3.10.2 as we do for it's framework test suite: ```shell pytest --ddtrace-patch-all tests -k 'not test_request_headers and not test_subdomain_route and not test_websocket_headers and not test_staticfiles_with_invalid_dir_permissions_returns_401' ``` Produces the following error: ``` _____________________________________________________________________________________________________________ test_wsgi_exc_info[asyncio] _____________________________________________________________________________________________________________ name = 'netrc', path = None, target = None > ??? E AttributeError: 'ImportHookFinder' object has no attribute 'find_spec' <frozen importlib._bootstrap>:939: AttributeError During handling of the above exception, another exception occurred: test_client_factory = functools.partial(<class 'starlette.testclient.TestClient'>, backend='asyncio', backend_options={}) > ??? /src/starlette/tests/middleware/test_wsgi.py:79: ``` This is because `wrapt`s `ImportHookFinder` did not define a `find_spec` method which was not required up until newer versions of Python. ## Checklist - [ ] Library documentation is updated. - [ ] [Corp site](https://github.com/DataDog/documentation/) documentation is updated (link to the PR). ## Reviewer Checklist - [x] Title is accurate. - [ ] Description motivates each change. - [x] No unnecessary changes were introduced in this PR. - [x] PR cannot be broken up into smaller PRs. - [x] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [x] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. - [ ] Add to milestone. (cherry picked from commit 5bd3f79) Co-authored-by: Brett Langdon <brett.langdon@datadoghq.com> Co-authored-by: Kyle Verhoog <kyle@verhoog.ca>
- Loading branch information
1 parent
642dc6d
commit 0c35234
Showing
9 changed files
with
320 additions
and
52 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
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,38 @@ | ||
# The inspect.formatargspec() function was dropped in Python 3.11 but we need | ||
# need it for when constructing signature changing decorators based on result of | ||
# inspect.getargspec() or inspect.getfullargspec(). The code here implements | ||
# inspect.formatargspec() base on Parameter and Signature from inspect module, | ||
# which were added in Python 3.6. Thanks to Cyril Jouve for the implementation. | ||
|
||
try: | ||
from inspect import Parameter, Signature | ||
except ImportError: | ||
from inspect import formatargspec | ||
else: | ||
def formatargspec(args, varargs=None, varkw=None, defaults=None, | ||
kwonlyargs=(), kwonlydefaults={}, annotations={}): | ||
if kwonlydefaults is None: | ||
kwonlydefaults = {} | ||
ndefaults = len(defaults) if defaults else 0 | ||
parameters = [ | ||
Parameter( | ||
arg, | ||
Parameter.POSITIONAL_OR_KEYWORD, | ||
default=defaults[i] if i >= 0 else Parameter.empty, | ||
annotation=annotations.get(arg, Parameter.empty), | ||
) for i, arg in enumerate(args, ndefaults - len(args)) | ||
] | ||
if varargs: | ||
parameters.append(Parameter(varargs, Parameter.VAR_POSITIONAL)) | ||
parameters.extend( | ||
Parameter( | ||
kwonlyarg, | ||
Parameter.KEYWORD_ONLY, | ||
default=kwonlydefaults.get(kwonlyarg, Parameter.empty), | ||
annotation=annotations.get(kwonlyarg, Parameter.empty), | ||
) for kwonlyarg in kwonlyargs | ||
) | ||
if varkw: | ||
parameters.append(Parameter(varkw, Parameter.VAR_KEYWORD)) | ||
return_annotation = annotations.get('return', Signature.empty) | ||
return str(Signature(parameters, return_annotation=return_annotation)) |
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
Oops, something went wrong.