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
1c68c987b0
Python: Change all remaining occurrences of StrConst
...
Done using
```
git grep StrConst | xargs sed -i 's/StrConst/StringLiteral/g'
```
2024-04-22 12:00:09 +00:00
Kasper Svendsen
3eb5a95ee3
Python: Make implicit this receivers explicit
2023-05-03 12:16:21 +02:00
Rasmus Lerchedahl Petersen
72e97918e9
python: format
2023-03-20 14:11:10 +01:00
Rasmus Lerchedahl Petersen
5f438e433d
python: exclude nonlocals from query
2023-03-20 13:34:39 +01:00
Josh Soref
f19a5c43f0
spelling: uninitialized
...
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com >
2022-10-13 11:21:10 -04:00
erik-krogh
6fdfd40880
changes to address reviews
2022-10-07 22:31:00 +02:00
erik-krogh
944ca4a0da
fix some more style-guide violations in the alert-messages
2022-10-07 11:23:34 +02:00
erik-krogh
014dcd1454
fixup a Python query, it didn't select something with a location
2022-08-24 16:23:20 +02:00
erik-krogh
d96d6721ba
change the alert message of unused-local-variable
2022-08-23 11:15:11 +02:00
Taus
d2603884ca
Python: Fix a bunch of class QLDoc
2022-03-07 18:59:49 +00:00
Taus
af7f532212
Python: Fix up a bunch of function QLDoc
2022-03-07 18:59:49 +00:00
Taus
20710616c5
Python: Fix "use set literal" warnings
2022-03-04 12:26:36 +00:00
Erik Krogh Kristensen
4e8e3a7420
simplify expressions that could be type-casts
2022-01-20 10:41:35 +01:00
Taus
233ae5a54b
Python: Fix FP in py/unused-local-variable
...
This is only a temporary fix, as indicated by the TODO comment.
The real underlying issue is the fact that `isUnused` is defined in
terms of the underlying SSA variables (as these are only created
for variables that are actually used), and the fact that annotated
assignments are always considered to redefine their targets, which may
not actually be the case.
Thus, the correct fix would be to change the extractor to _disregard_
mere type annotations for the purposes of figuring out whether an
SSA variable should be created or not.
However, in the short term the present fix is likely sufficient.
2021-07-20 12:13:44 +00:00
Chris Smowton
455b840712
Fix all dead qhelp links
...
For those documents with no obvious new home I've pointed the links to the Internet Archive.
2021-04-23 15:20:21 +01:00
Marcono1234
5a8ffa5a85
Use .inc.qhelp extension for included help files
2021-03-04 22:04:48 +01:00
Rasmus Wriedt Larsen
3fe715abb6
Python: Fix query names that inclde __ (dunder)
...
Without backticks, the text UNDERSCORE UNDERSCORE eq UNDERSCORE UNDERSCORE would
be considered to make things bold in our markdown output, making the query info
look strange.
Example https://codeql.github.com/codeql-query-help/python/py-slots-in-old-style-class/
2021-02-04 15:49:37 +01:00
Taus Brock-Nannestad
f07a7bf8cf
Python: Autoformat everything using qlformat.
...
Will need subsequent PRs fixing up test failures (due to deprecated
methods moving around), but other than that everything should be
straight-forward.
2020-07-07 15:43:52 +02:00
Taus Brock-Nannestad
01fb1e3786
Python: Get rid of deprecated terms in code and .qhelp.
2020-06-19 16:51:09 +02:00
Rasmus Wriedt Larsen
721713b9e1
Python: Minor fixes from code review
...
Co-authored-by: Taus <tausbn@gmail.com >
2020-06-10 16:14:21 +02:00
Rasmus Wriedt Larsen
7c037cd2ab
Python: Handle Enum._convert in Python 3.8
2020-06-08 14:49:58 +02:00
Taus
7716cff3d8
Merge pull request #3551 from RasmusWL/python-fix-upcoming-deprecation
...
Python: Fix (upcoming) deprecation compiler-warnings
2020-05-25 16:17:57 +02:00
Rasmus Wriedt Larsen
f602f3e1c7
Python: Use proper import for semmle.python.dataflow.TaintTracking
...
It was moved in 637677d515 , but imports were not
updated.
2020-05-25 13:45:49 +02:00
Rasmus Wriedt Larsen
6ce1b9f7fa
Python: Fix use of StrConst.strValue()
2020-05-25 13:12:56 +02:00
Rasmus Wriedt Larsen
70634fe30e
Python: Remove usage of deprecated .getValue()
2020-03-06 16:20:31 +01:00
Rasmus Wriedt Larsen
96d5703f2c
Python: Remove use of deprecated methods
2020-01-22 13:45:14 +01:00
Rasmus Wriedt Larsen
5d01cb7c28
Python: Fix bad QL-rewriting
...
Original code:
exists(Expr e, For forloop | forloop = loop and e.pointsTo(_, _, capturing) |
not loop.contains(e)
)
The new version will preserve the same semantics. The problem with the first
rewrite was that `not loop.(For).somethingMore` would hold for any AstNode that
was not a For
2020-01-06 13:30:37 +01:00
Rasmus Wriedt Larsen
92e272cc03
Python: Address comments for modernising Variables/
2019-12-20 15:58:51 +01:00
Rasmus Wriedt Larsen
b8a9a353b8
Python: Autoformat Variables/*
2019-12-20 15:08:20 +01:00
Rasmus Wriedt Larsen
25ab0ed20f
Python: Modernise Variables/MonkeyPatched.qll
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
58bb16e5dd
Python: Modernise Variables/Undefined.qll
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
34f9135492
Python: Modernise py/unused-parameter
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
aba3ac7b66
Python: Modernise py/uninitialized-local-variable
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
697a006ef2
Python: Modernise py/undefined-global-variable
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
3ffea599f1
Python: Rewrite casts for py/undefined-global-variable
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
81e27aab8d
Python: Modernise py/unused-loop-variable
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
8f7ba0a06d
Python: Modernise py/local-shadows-global
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
9f4088413a
Python: Modernise py/local-shadows-builtin
...
+ moved `scope instanceof Function` so it makes more sense :)
2019-12-20 15:05:49 +01:00
Rasmus Wriedt Larsen
6a73479ea3
Python: Modernise py/loop-variable-capture
2019-12-16 13:36:59 +01:00
Taus Brock-Nannestad
d2f985038c
Python: Fix missing modernisation.
2019-11-04 10:48:42 +01:00
Taus Brock-Nannestad
ab2c8f312c
Python: Apply autoformat.
2019-10-21 17:40:36 +02:00
Taus Brock-Nannestad
4fe1ba0ea4
Python: Refactor py/undefined-export for more clarity.
2019-10-21 17:40:36 +02:00
Taus Brock-Nannestad
8a1d1e7b7a
Python: Modernise and false positive in py/undefined-export.
2019-10-21 16:07:48 +02:00
semmle-qlci
e36e16af48
Merge pull request #2079 from taus-semmle/python-unused-local-nonlocal
...
Approved by RasmusWL
2019-10-07 15:38:21 +01:00
Taus Brock-Nannestad
26da6a1178
Python: Apply autoformat.
2019-10-03 17:58:52 +02:00
Taus Brock-Nannestad
5946a4a066
Python: Teach py/unused-local-variable about nonlocal.
2019-10-03 17:56:29 +02:00
alexey
70eca91d28
Add tags tag to a Python query
2019-09-27 12:36:38 +01:00
Mark Shannon
955e54b360
Python: Update unitialized local to use new taint-tracking config.
2019-08-29 10:31:50 +01:00
Mark Shannon
7bbe39ef01
Python: Don't report uninitialized locals in unreachable code.
2019-06-25 15:52:48 +01:00