-
Notifications
You must be signed in to change notification settings - Fork 2k
Python: Fix import of refined variable #12244
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
27e2307
Python: Add import regression for refined variable
RasmusWL fb425b7
Python: Add import test of `py/insecure-protocol`
RasmusWL 00eec69
Python: Allow import of refined variable
RasmusWL e522009
Python: More complex import examples
RasmusWL 4a66e48
Python: Allow import resolution with recursive phi/refine steps
RasmusWL 6a5eebe
Python: Add test of `module_export`
RasmusWL 6ba39d5
Python: Add import regression for re-exported things
RasmusWL 4df7dfb
Python: Don't import module as module_attr
RasmusWL d77ce4f
Python: minor rewrite of `from <pkg> import *` handling
RasmusWL be5812c
Python: `from <pkg> import *` ignores `__all__` regression
RasmusWL c8a7624
Python: Take `__all__` into consideration for re-export of `from <pkg…
RasmusWL 8eaaf8e
Python: Ignore `trace.py` in `ModuleExport.ql` test
RasmusWL 321a4b4
Python: `ModuleExport.ql` test: ignore `main.py`
RasmusWL bea0acb
Python: Add barrier test to import resolution
RasmusWL 97fefd2
Python: Attempt to fix import flow
RasmusWL 3739072
Python: Fixed most problems from last commit
RasmusWL 13ae98e
Python: Fix submodule exported under wrong name (when attribute clash)
RasmusWL 96c0d95
Python: Illustrate that `clashing_attr` can be submodule
RasmusWL b7bdc55
Python: Show import resolution is a bit generous with exported value
RasmusWL 11000fd
Python: Fix `ModuleExport.ql` test for Python 2
RasmusWL be7d668
Merge branch 'main' into import-refined
RasmusWL 35bd809
Merge branch 'main' into import-refined
RasmusWL 2cc8fba
Python: Accept changes due to better import resolution of `operator.py`
RasmusWL 93c9f59
Python: Extract version specific coverage/classes.py tests
RasmusWL 2ee09cc
Merge branch 'main' into import-refined
RasmusWL e90559b
Python: Add missing `options` files
RasmusWL b2f34ef
Merge branch 'main' into import-refined
RasmusWL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
python/ql/lib/change-notes/2023-02-17-import-refined-variable.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --- | ||
| category: minorAnalysis | ||
| --- | ||
| * Fixed module resolution so we allow imports of definitions that have had an attribute assigned to it, such as `class Foo; Foo.bar = 42`. |
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
Empty file.
1 change: 1 addition & 0 deletions
1
python/ql/test/experimental/dataflow/coverage-py2/argumentRoutingTest.qlref
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../coverage/argumentRoutingTest.ql |
54 changes: 54 additions & 0 deletions
54
python/ql/test/experimental/dataflow/coverage-py2/classes.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Python 2 specific tests, like the one in coverage/classes.py | ||
| # | ||
| # User-defined methods, both instance methods and class methods, can be called in many non-standard ways | ||
| # i.e. differently from simply `c.f()` or `C.f()`. For example, a user-defined `__await__` method on a | ||
| # class `C` will be called by the syntactic construct `await c` when `c` is an instance of `C`. | ||
| # | ||
| # These tests should cover all the class calls that we hope to support. | ||
| # It is based on https://docs.python.org/3/reference/datamodel.html, and headings refer there. | ||
| # | ||
| # All functions starting with "test_" should run and execute `print("OK")` exactly once. | ||
| # This can be checked by running validTest.py. | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname((__file__)))) | ||
| from testlib import expects | ||
|
|
||
|
|
||
| def SINK1(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK2(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK3(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK4(x): | ||
| pass | ||
|
|
||
|
|
||
| def OK(): | ||
| print("OK") | ||
|
|
||
|
|
||
| # 3.3.8. Emulating numeric types | ||
|
|
||
| # object.__index__(self) | ||
| class With_index: | ||
| def __index__(self): | ||
| SINK1(self) | ||
| OK() # Call not found | ||
| return 0 | ||
|
|
||
|
|
||
| def test_index(): | ||
| import operator | ||
|
|
||
| with_index = With_index() #$ MISSING: arg1="SSA variable with_index" func=With_index.__index__ | ||
| operator.index(with_index) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| semmle-extractor-options: --max-import-depth=1 --lang=2 |
Empty file.
1 change: 1 addition & 0 deletions
1
python/ql/test/experimental/dataflow/coverage-py3/argumentRoutingTest.qlref
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../coverage/argumentRoutingTest.ql |
72 changes: 72 additions & 0 deletions
72
python/ql/test/experimental/dataflow/coverage-py3/classes.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Python 3 specific tests, like the one in coverage/classes.py | ||
| # | ||
| # User-defined methods, both instance methods and class methods, can be called in many non-standard ways | ||
| # i.e. differently from simply `c.f()` or `C.f()`. For example, a user-defined `__await__` method on a | ||
| # class `C` will be called by the syntactic construct `await c` when `c` is an instance of `C`. | ||
| # | ||
| # These tests should cover all the class calls that we hope to support. | ||
| # It is based on https://docs.python.org/3/reference/datamodel.html, and headings refer there. | ||
| # | ||
| # All functions starting with "test_" should run and execute `print("OK")` exactly once. | ||
| # This can be checked by running validTest.py. | ||
|
|
||
| import sys | ||
| import os | ||
|
|
||
| sys.path.append(os.path.dirname(os.path.dirname((__file__)))) | ||
| from testlib import expects | ||
|
|
||
|
|
||
| def SINK1(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK2(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK3(x): | ||
| pass | ||
|
|
||
|
|
||
| def SINK4(x): | ||
| pass | ||
|
|
||
|
|
||
| def OK(): | ||
| print("OK") | ||
|
|
||
|
|
||
|
|
||
| # 3.3.7. Emulating container types | ||
|
|
||
| # object.__length_hint__(self) | ||
| class With_length_hint: | ||
| def __length_hint__(self): | ||
| SINK1(self) | ||
| OK() | ||
| return 0 | ||
|
|
||
|
|
||
| def test_length_hint(): | ||
| import operator | ||
|
|
||
| with_length_hint = With_length_hint() #$ arg1="SSA variable with_length_hint" func=With_length_hint.__length_hint__ | ||
| operator.length_hint(with_length_hint) | ||
|
|
||
|
|
||
| # 3.3.8. Emulating numeric types | ||
|
|
||
| # object.__index__(self) | ||
| class With_index: | ||
| def __index__(self): | ||
| SINK1(self) | ||
| OK() # Call not found | ||
| return 0 | ||
|
|
||
|
|
||
| def test_index(): | ||
| import operator | ||
|
|
||
| with_index = With_index() #$ arg1="SSA variable with_index" func=With_index.__index__ | ||
| operator.index(with_index) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| semmle-extractor-options: --max-import-depth=1 --lang=3 |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.