FIX: handling multi-target (from-)import statements#434
Open
TTsangSC wants to merge 5 commits into
Open
Conversation
line_profiler/autoprofile/
ast_tree_profiler.py::AstTreeProfiler.profile()
Updated implementation to account for multiple import targets
in the same (from-)import statement
profmod_extractor.py
- Removed unused typing imports
- Updated implementation and return type of
`ProfmodExtractor.run()` to account for multiple import
targets in the same (from-)import statement
XXX:
should we add a switch for `ProfmodExtractor.run()` so that it
behaves as before by default?
CHANGELOG.rst
Added entry
tests/test_autoprofile.py::test_multitarget_import_resolution()
New parametrized test testing that issue pyutils#433 has been fixed
line_profiler/autoprofile/ast_tree_profiler.py::AstTreeProfiler
__init__()
Updated type hints for `ast_transformer_class_handler` and
`profmod_extractor_class_handler` to be more specific
profile()
Updated call to `ProfmodExtractor.run()` to include
`assume_single_target_imports=False` (see below)
line_profiler/autoprofile/profmod_extractor.py::ProfmodExtractor.run()
Updated call signature:
- New parameter `assume_single_target_imports` defauling to true,
restoring the legacy behavior
- If `assume_single_target_imports` is true, a `DeprecationWarning`
is issued; and if it results in an valid profiling target being
dropped, a `UserWarning` is issued
- If false, the new behavior (returning a `dict[int, list[str]]`) is
used
tests/test_autoprofile.py::test_profmod_extractor_multitarget_behavior()
New parametrized test to cover the aforementioned warning behavior,
ensure that backward compatibility is retained while users are
warned against the shortcomings
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #434 +/- ##
==========================================
+ Coverage 82.40% 83.97% +1.57%
==========================================
Files 20 20
Lines 2256 2278 +22
Branches 359 364 +5
==========================================
+ Hits 1859 1913 +54
+ Misses 300 268 -32
Partials 97 97
... and 2 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or 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
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.
Closes #433.
Changes
assume_single_target_importstoline_profiler.autoprofile.profmod_extractor.ProfmodExtractor.run():True(default) retains the old behavior (method returnsdict[int, str]), but issues (1) aDeprecationWarning, and (2) in addition aUserWarningwhen this results in profiling targets being droppedFalsechanges the return type todict[int, list[str]], so as to properly handle statements likefrom foo import spam, ham, eggs as jam.line_profiler.autoprofile.ast_tree_profiler.AstTreeProfilerhas been correspondingly updated to insertprof.add_imported_function_or_module()statements for each eligible target in multi-target imports.tyconfig line topyproject.tomlto guard against v0.0.52's making redundant casts an error.tests/test_autoprofile.pyto verify the fixes:test_multitarget_import_resolution()checks thatAstTreeProfiler.profile()now correctly transforms ASTs with multi-target import statements.test_profmod_extractor_multitarget_behavior()checks thatProfmodExtractor.run()'s return type and warning issuance are as aformentioned.