Commit Graph

118 Commits

Author SHA1 Message Date
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
Taus
bf688b88a9 Python: Add missing special methods 2025-03-14 16:29:54 +00:00
Taus
f3353dc3fb Python: Ignore special methods with placeholder bodies
Instances of this include
- Bodies that contain just a docstring (common in Zope interfaces)
- Bodies that do nothing but raise an exception.
2025-03-13 12:18:43 +00:00
Taus
862b89207d Python: Disable "usused default" logic
Adds a new boolean parameter `is_unused_default` that indicates whether
the given result is one where a parameter to a special method has a
default value (which will never be used when invoked in the normal way).
These results are somewhat less useful (because the special method
_might_ be invoked directly, in which case the default value would still
be relevant), but it seemed like a shame to simply remove the code, so
instead I opted to disable it in this way.
2025-03-13 12:18:43 +00:00
Taus
24b2eb24c1 Python: Refactor special method query
Moves a bunch of `owner.declaredAttribute(name) = f` instances to the
top level, in the process greatly cleaning up the code. The behaviour
should be the unchanged.

Having done this, there's only one place where we depend on points-to,
and that's in the remaining `declaredAttribute` call. This should
greatly simplify the move away from points to.
2025-03-13 12:18:43 +00:00
Joe Farebrother
f46a2a1773 Exclude some decorators 2025-02-12 09:40:45 +00:00
Joe Farebrother
61d5a692fb Refactor metaclass logic a bit, ensure lambdas are excluded 2025-02-07 21:46:30 +00:00
Joe Farebrother
287cf0121d Fix docs 2025-02-04 15:28:13 +00:00
Joe Farebrother
3802a73f47 Update docs 2025-02-04 14:46:02 +00:00
Joe Farebrother
e8adef18a3 Update to inline expectations + fixes 2025-02-04 14:45:59 +00:00
Joe Farebrother
0bf8d4ec4b Exclude 'methods' used in initialisation, and allow self for metaclass methods 2025-02-04 14:45:52 +00:00
Joe Farebrother
fa76bf3c9f Fix formatting and rewrite redundant exists 2025-02-04 14:45:48 +00:00
Joe Farebrother
526e235fc1 Update NonSelf and NonCls queries 2025-02-04 14:45:44 +00:00
Rasmus Wriedt Larsen
ce6335866b Python: Move ModificationOfParameterWithDefault to new dataflow API 2023-08-28 16:19:47 +02:00
erik-krogh
944ca4a0da fix some more style-guide violations in the alert-messages 2022-10-07 11:23:34 +02:00