Commit Graph

132 Commits

Author SHA1 Message Date
Joe Farebrother
f3802ec60f Merge pull request #20217 from joefarebrother/python-qual-signature-mismatch
Python: Modernize the Signature Mismatch query
2025-09-17 13:29:33 +01:00
Michael Nebel
7c0aa78e39 Python: Add many medium precision queries to the code-quality-extended suite. 2025-09-10 16:06:38 +02:00
Joe Farebrother
f9e094de61 Simplify choosaASignatureMismatchWitness for improved performance 2025-09-09 17:25:48 +01:00
Joe Farebrother
eb246f6f71 Performance experiment - add getFunctionFIle for better join order 2025-09-08 09:43:22 +01:00
Joe Farebrother
71dec0b23e Fix typos 2025-09-03 11:22:46 +01:00
Joe Farebrother
9fa630faf5 Add comments documenting helper predicates, and add call resolve condition to callMatchesSignature to avoid cartesian product 2025-09-03 11:00:59 +01:00
Joe Farebrother
318d1cd392 Increase precision in detecting call matches signature 2025-09-02 12:02:08 +01:00
Joe Farebrother
125c6534b7 Use new option name 2025-09-01 23:41:28 +01:00
Joe Farebrother
6587ad435e Update python/ql/src/Functions/SignatureOverriddenMethod.ql
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-09-01 16:31:24 +01:00
Joe Farebrother
0a83c11f42 Add changenote.+ fix typo 2025-09-01 16:31:18 +01:00
Joe Farebrother
900a5cd9d7 Update documentation 2025-09-01 16:31:11 +01:00
Joe Farebrother
2bbf24b3ea Add additional test cases 2025-09-01 16:30:53 +01:00
Joe Farebrother
f429b9038c Update tests, update alert messages 2025-09-01 16:30:44 +01:00
Joe Farebrother
067c98d3ee Include conditional alert messages for various cases 2025-09-01 16:30:35 +01:00
Joe Farebrother
4212d1b5b6 Update alert messages and choose one witness 2025-09-01 16:30:26 +01:00
Joe Farebrother
5ba5007076 Modernize signature mismatch 2025-09-01 16:30:17 +01:00
Joe Farebrother
ada0b372c6 Merge pull request #20120 from joefarebrother/python-qual-unexpected-raise-special
Python: Modernize Unexpected Raise In Special Method query
2025-08-27 15:01:46 +01:00
Joe Farebrother
5b0beb91d1 Update python/ql/src/Functions/IncorrectRaiseInSpecialMethod.qhelp
Co-authored-by: Taus <tausbn@github.com>
2025-08-27 13:19:55 +01:00
Joe Farebrother
d8083add3e Doc updates 2025-08-01 12:35:01 +01:00
Joe Farebrother
c0da9c407e Fix typo in test dir name + update examples 2025-07-25 13:15:46 +01:00
Joe Farebrother
958fddb638 cleanup order and remove duplicates for arithmetic methods 2025-07-25 10:57:19 +01:00
Joe Farebrother
d7b855c4e3 qhelp fix 2025-07-25 10:24:58 +01:00
Joe Farebrother
9af2ab83dc Cleanups 2025-07-25 10:22:51 +01:00
Joe Farebrother
8bdf6801b3 Add qldoc 2025-07-25 10:05:09 +01:00
Joe Farebrother
3525e83ad2 Add changenote + some doc updates 2025-07-25 09:52:54 +01:00
Joe Farebrother
871688f026 Update docs 2025-07-24 16:01:57 +01:00
Joe Farebrother
362bfba049 Update unit tests 2025-07-24 14:50:36 +01:00
Joe Farebrother
b9f6657ade Remove use of toString. This does also reduce reaults from cases where the exception is not a simple identifier. 2025-07-24 13:50:27 +01:00
Joe Farebrother
b9738066de try excluding set methods, add methods, update alert messages 2025-07-24 11:18:28 +01:00
Joe Farebrother
73d257e538 Port unexpected raise away from pointsto 2025-07-23 14:13:58 +01:00
Joe Farebrother
909f57261c Minor doc updates; updating python 2 references to python 3 and updating grammar 2025-07-15 13:26:46 +01:00
Joe Farebrother
c8c92a7139 Update tags for mixed-tuple-returns to include exactly 1 subcategory 2025-06-19 14:09:00 +01:00
Joe Farebrother
c3f7b18055 Review suggestions - update some tags 2025-06-19 14:08:51 +01:00
Joe Farebrother
02f8ec33f2 Tag 'type-checking'-like quality queries 2025-06-19 14:07:55 +01:00
Joe Farebrother
869e33e38c Tag 'linter-like' quality queries that use pointto
Excluded for now: unnecassary-delete; since the pattern is often intentional to break reference cycles, which the query doesn't account for; so uncertain about its claim of high precision
2025-06-19 14:07:15 +01:00
Joe Farebrother
5c4548df45 Tag more quality queries.
Excluded for now for uncertainty: incomplete ordering, import deprecated module
2025-06-19 14:06:57 +01:00
Joe Farebrother
049c0705a9 Tag quality queries that are high precision and dont use pointsto 2025-06-19 14:06:46 +01:00
Joe Farebrother
73f2770acb Fix handling for some wrappers + add test case 2025-05-30 11:24:06 +01:00
Joe Farebrother
f3a5608b06 Apply review suggestions - remove methodOfClass, fix qhelp typo; additionally add some more doc comments 2025-05-27 13:35:13 +01:00
Joe Farebrother
c070d04231 Fix qhelp 2025-05-23 14:31:13 +01:00
Joe Farebrother
b15fec0fb9 Fix qhelp and tests 2025-05-23 14:17:21 +01:00
Joe Farebrother
44a678a3f4 remove redundant import 2025-05-23 13:16:13 +01:00
Joe Farebrother
f27057a747 Update qhelp 2025-05-23 10:56:43 +01:00
Joe Farebrother
7b452a1611 Add case for wrappers 2025-05-22 09:01:15 +01:00
Joe Farebrother
bedd44a287 Update query and add case for iter(self.__next__, None) 2025-05-21 11:02:24 +01:00
Tamas Vajk
fdeac95714 Use code-quality-selectors in Python suite 2025-04-29 16:23:22 +02: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
2dcd7895ec Python: Modernise py/mixed-tuple-returns
Removes the dependence on points-to in favour of an approach based on
(local) data-flow.

I first tried a version that used type tracking, as this more accurately
mimics the behaviour of the old query. However, I soon discovered that
there were _many_ false positives in this setup. The main bad pattern I
saw was a helper function somewhere deep inside the code that both
receives and returns an argument that can be tuples with different sizes
and origins. In this case, global flow produces something akin to a
cartesian product of "n-tuples that flow into the function" and
"m-tuples that flow into the function" where m < n.

To combat this, I decided to instead focus on only flow _within_ a given
function (and so local data-flow was sufficient).

Additionally, another class of false positives I saw was cases where the
return type actually witnessed that the function in question could
return tuples of varying sizes. In this case it seems reasonable to not
flag these instances, since they are already (presumably) being checked
by a type checker.

More generally, if you've annotated the return type of the function with
anything (not just `Tuple[...]`), then there's probably little need to
flag it.
2025-03-27 15:27: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