Commit Graph

3959 Commits

Author SHA1 Message Date
Taus
579cf4a65a Merge pull request #19424 from github/tausbn/python-extract-hidden-file-by-default
Python: Extract files in hidden dirs by default
2025-05-16 14:43:47 +02:00
Taus
2ded42c285 Python: Update extractor tests 2025-05-02 14:27:46 +00:00
Napalys Klicius
f652686607 Merge pull request #19444 from Napalys/python/hdbcli
Python: modeling of `hdbcli`
2025-05-01 17:58:31 +02:00
Napalys Klicius
e1fc0ca051 Added implementation hdbcli as part of PEP249::PEP249ModuleApiNode 2025-05-01 14:18:02 +02:00
Napalys Klicius
0325f368fe Added test case for hdbcli 2025-05-01 13:57:14 +02:00
yoff
531f2a15a4 python: model send_header from http.server 2025-04-30 19:58:14 +02:00
Joe Farebrother
7f7fca9e27 Merge pull request #19165 from joefarebrother/python-qual-loop-var-capture
Python: Modernize the Loop Variable Capture query
2025-04-10 13:07:05 +01:00
Joe Farebrother
b5805503fe Cleanups 2025-04-04 11:56:07 +01:00
Joe Farebrother
9fb1c31206 Update tests to inline expectations 2025-04-04 10:13:39 +01:00
Joe Farebrother
adfe89fadc Update test output 2025-04-04 09:47:21 +01:00
Taus
aacdc70a73 Merge pull request #19136 from github/tausbn/python-modernise-mixed-tuple-returns-query
Python: Modernize `py/mixed-tuple-returns`
2025-04-01 17:31:56 +02:00
Taus
840abbf5b1 Merge pull request #18956 from github/tausbn/python-more-special-method-query-refactoring
Python: Modernize special method query
2025-03-28 17:11:24 +01:00
Taus
6674288fd2 Python: Update test cases
Adds a comment explaining why we no longer flag the indirect tuple
example.
Also adds a test case which _would_ be flagged if not for the type
annotation.
2025-03-28 15:12:39 +00:00
Taus
f601f4ad9b Python: Update test expectations
As we're no longer tracking tuples across function boundaries, we lose
the result that related to this setup (which, as the preceding commit
explains, lead to a lot of false positives).
2025-03-27 15:31:28 +00:00
Joe Farebrother
3707f107bf Fix tests + add more tests 2025-03-20 11:35:38 +00:00
Joe Farebrother
b2acfbcf87 Simplify handling of wrapper classes and exception flow + improve qldoc and annotate tests. 2025-03-20 11:35:18 +00:00
Joe Farebrother
f750e22d91 Add case for exception flow 2025-03-20 11:35:01 +00:00
Joe Farebrother
ecb3050780 Update tests 2025-03-20 11:34:42 +00:00
Taus
ef9b229023 Python: Actually get rid of points-to
Also adds `quality` to the list of tags for the query.
2025-03-14 16:51:48 +00:00
Taus
c9e9deb41e Python: Adapt to a points-to-less world
Technically we still depend on points-to in that we still mention
`PythonFunctionValue` and `ClassValue` in the query. However, we
immediately move to working with the corresponding `Function` and
`Class` AST nodes, and so we're not really using points-to. (The reason
for doing things this way is that otherwise the `.toString()` for all of
the alerts would change, which would make the diff hard to interpret.
This way, it should be fairly simple to see which changes are actually
relevant.)

We do lose some precision when moving away from points-to, and this is
reflected in the changes in the `.expected` file. In particular we no
longer do complicated tracking of values, but rather look at the
syntactic structure of the classes in question. This causes us to lose
out on some results where a special method is defined elsewhere, and
causes a single FP where a special method initially has the wrong
signature, but is subsequently overwritten with a function with the
correct signature.

We also lose out on results having to do with default values, as these
are now disabled.

Finally, it was necessary to add special handling of methods marked with
the `staticmethod` decorator, as these expect to receive fewer
arguments. This was motivated by a MRVA run, where e.g. sympy showed a
lot of examples along the lines of
```
@staticmethod
def __abs__():
   return ...
```
2025-03-14 16:49:33 +00:00
Taus
3d643c02be Merge pull request #18921 from github/tausbn/python-fix-unused-global-variable-in-forward-annotation-fp
Python: Add support for forward references in unused var query
2025-03-13 16:37:25 +01:00
Taus
6546bb1b1d Merge branch 'main' into tausbn/python-fix-match-pruning-logic 2025-03-06 14:37:58 +01:00
Taus
88615f427b Python: Add support for forward declarations in unused var query
Fixes the false positive reported in
https://github.com/github/codeql/issues/18910

Adds a new `Annotation` class (subclass of `Expr`) which encompasses all
possible kinds of annotations in Python.

Using this, we look for string literals which are part of an annotation,
and which have the same content as the name of a (potentially) unused
global variable, and in that case we do not produce an alert.

In future, we may want to support inspecting such string literals more
deeply (e.g. to support stuff like "list[unused_var]"), but I think for
now this level of support is sufficient.
2025-03-04 14:41:45 +00:00
Taus
301ebcb12b Python: Extend test cases for "unused global var" query
Adds two test cases having to do with type annotations. The first one
demonstrates that type annotations (even if they are never executed by
the Python interpreter) count as uses for the purposes of the unused
variable query. The second one demonstrates that this is _not_ the case
if all such uses are inside strings (i.e. forward declarations), as we
do not currently inspect the content of these strings.
2025-03-04 13:52:31 +00:00
Joe Farebrother
180e45d66a Merge pull request #18599 from joefarebrother/python-qual-not-named-self-cls
Python: Modernize py/not-named-self and py/not-named-cls queries
2025-02-17 08:58:34 +00:00
Joe Farebrother
f46a2a1773 Exclude some decorators 2025-02-12 09:40:45 +00:00
yoff
158430af82 Merge pull request #17765 from yoff/python/test-functional-behaviour
Python: Add tests for functional-like programming
2025-02-11 16:28:37 +01:00
Taus
918c05c538 Python: Don't prune any MatchLiteralPatterns
Extends the mechanism introduced in
https://github.com/github/codeql/pull/18030
to behave the same for _all_ `MatchLiteralPattern`s, not just the ones
that happen to be the constant `True` or `False`.

Co-authored-by: yoff <yoff@github.com>
2025-02-11 12:58:52 +00:00
Joe Farebrother
61d5a692fb Refactor metaclass logic a bit, ensure lambdas are excluded 2025-02-07 21:46:30 +00:00
Taus
131ec8d22f Python: Handle loop constructs outside of loops
Observed on some test files in Nuitka/Nuitka, having `break` and
`continue` outside of loops in Python is (to Python) a syntax error, but
our parser happily accepted this broken syntax.

This then caused issues further downstream in the control-flow
construction, as it broke some invariants.

To fix this we now skip the code that would previously fail when the
invariants are broken.

Co-authored-by: yoff <yoff@github.com>
2025-02-06 14:30:16 +00:00
Joe Farebrother
e8adef18a3 Update to inline expectations + fixes 2025-02-04 14:45:59 +00:00
Joe Farebrother
aa2c84ea36 Move tests to separate folder 2025-02-04 14:45:56 +00:00
Joe Farebrother
d248fbfe57 Merge pull request #18301 from joefarebrother/python-model-missing-builtins
Python: Add models for builtins `map`, `filter`, `zip`, and `enumerate`.
2025-01-20 16:39:37 +00:00
Paolo Tranquilli
4ab5650979 Python: add some more FP tests around match 2025-01-17 11:01:00 +01:00
Joe Farebrother
2aea356756 Add change note + fix tests 2025-01-15 10:24:18 +00:00
Joe Farebrother
6a6585e415 Add tests for zip and enumerate 2025-01-15 09:57:15 +00:00
Joe Farebrother
460de3f7d5 Reduce generality of map and zip for performance 2025-01-14 09:39:57 +00:00
Joe Farebrother
4e36008ed9 Add tests 2025-01-14 09:39:56 +00:00
Joe Farebrother
a7fb73a2b2 Merge pull request #18185 from joefarebrother/python-lxml
Python: Model additional flow steps for the lxml framework
2025-01-10 13:40:16 +00:00
Joe Farebrother
35961e454b Fix tests to check for the correct type 2025-01-07 15:23:07 +00:00
Rasmus Wriedt Larsen
34631a8784 Python: Model FastAPI requests
Co-authored-by: Joe Farebrother <joefarebrother@github.com>
2024-12-18 15:58:51 +01:00
Rasmus Wriedt Larsen
79dfbf7b21 Python: Add FastAPI request test
Co-authored-by: Joe Farebrother <joefarebrother@github.com>
2024-12-18 15:48:29 +01:00
Joe Farebrother
dcbcf7e2bd Add additional tests demonstrating false negative flow 2024-12-12 15:55:36 +00:00
Michael Nebel
2321ca59f6 Python: Update all test util paths to point to the new location. 2024-12-12 13:54:30 +01:00
Michael Nebel
1490400ab0 Python: Move test utilities into the query pack. 2024-12-12 13:54:28 +01:00
Joe Farebrother
2019ddfa7f Qldoc improvements + add a few extra tests 2024-12-11 12:25:40 +00:00
Joe Farebrother
bcb08bbc7b Update test output 2024-12-10 19:24:05 +00:00
Joe Farebrother
29a90235e8 Improve tests and use API graphs 2024-12-10 19:09:45 +00:00
Joe Farebrother
d2ed92d6d0 Added tests 2024-12-10 19:09:20 +00:00
Joe Farebrother
f82fa20249 Update test outputs 2024-12-09 20:37:11 +00:00