-
Notifications
You must be signed in to change notification settings - Fork 418
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
chore(internal): better support for Python legacy versions in ModuleWatchdog #4083
Merged
mergify
merged 7 commits into
DataDog:1.x
from
P403n1x87:chore/module-better-legacy-support
Aug 16, 2022
Merged
chore(internal): better support for Python legacy versions in ModuleWatchdog #4083
mergify
merged 7 commits into
DataDog:1.x
from
P403n1x87:chore/module-better-legacy-support
Aug 16, 2022
Conversation
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
…atchdog This change improves support for Python legacy versions, like 2.7 and 3.5 by using a common loader wrapper that makes more attributes available upon request, e.g. is_package. Furthermore, this change also provides support for dict copy via the dict constructor, which is required by some pytest fixtures, like testdir.
P403n1x87
added
the
changelog/no-changelog
A changelog entry is not required for this PR.
label
Aug 13, 2022
14 tasks
P403n1x87
force-pushed
the
chore/module-better-legacy-support
branch
from
August 15, 2022 16:09
7683b21
to
9c5a5f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there any tests we can add to validate the copying is working as expected?
…atchdog This change improves support for Python legacy versions, like 2.7 and 3.5 by using a common loader wrapper that makes more attributes available upon request, e.g. is_package. Furthermore, this change also provides support for dict copy via the dict constructor, which is required by some pytest fixtures, like testdir.
P403n1x87
force-pushed
the
chore/module-better-legacy-support
branch
from
August 16, 2022 12:55
9c5a5f8
to
cfdcf67
Compare
…om/p403n1x87/dd-trace-py into chore/module-better-legacy-support
I've added a test case. |
P403n1x87
force-pushed
the
chore/module-better-legacy-support
branch
from
August 16, 2022 14:03
764c664
to
0bf6160
Compare
ZStriker19
approved these changes
Aug 16, 2022
Yun-Kim
approved these changes
Aug 16, 2022
brettlangdon
approved these changes
Aug 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This change improves support for Python legacy versions, like 2.7 and 3.5 by using a common loader wrapper that makes more attributes available upon request, e.g. is_package. Furthermore, this change also provides support for dict copy via the dict constructor, which is required by some pytest fixtures, like testdir.
More technical details
In Python<=3.5, calling the
dict
constructor on a dictionary makes a copy of it by first checking if it has akeys
attribute, and then performing aPyDict_Check
. If these checks succeed, the dictionary is copied using the C API. SinceModuleWatchdog
is a subclass ofdict
, this means that the wrapping logic is bypassed, anddict
ends up copying the dictionary backingModuleWatchdog
rather than the wrappedsys.modules
. We exploit thekeys
attribute access to then copy the state ofsys.modules
over to the backingdict
, so that callingdict
on aModuleWatchdog
instance actually creates a copy of the wrapped dictionary instead of the backing one.Testing
This change is a pre-requisite for #4070 to make the test suite pass.
Checklist
feat
andfix
pull requests.Reviewer Checklist
changelog/no-changelog
label added.