Граф коммитов

29 Коммитов

Автор SHA1 Сообщение Дата
Taus e2530cf14f Python: Update expected test output
Co-authored-by: yoff <lerchedahl@gmail.com>
2024-11-19 14:10:50 +00:00
Paolo Tranquilli 147d66b587
Merge branch 'main' into redsun82/python-match-fps 2024-11-07 09:46:32 +01:00
Rasmus Lerchedahl Petersen bb78c2a67e Python: update test expectations 2024-10-11 15:36:44 +02:00
Paolo Tranquilli daea773fce Python: tests with false positives around `match` 2024-06-14 17:28:35 +02:00
Rasmus Wriedt Larsen 721bde1ce8
Python: Delete orphaned `.expected` files 2023-11-15 09:59:26 +01:00
Nick Rolfe c67a350e36 Python: avoid selecting getLocation() in py/unnecessary-delete 2023-06-05 11:16:13 +01: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 7e0bd5bde4
update expected output of tests 2022-08-22 21:41:47 +02:00
Rasmus Wriedt Larsen 420dea0792 Python: Fix example TestCase 2022-05-30 14:48:06 +02:00
Taus 5d4db3af15 Python: Extend unreachable statement test
Adds a test demostrating the false positive observed by andersfugmann.

Note that this does not change the `.expected` file, and so the tests
will fail. This is expected.
2022-01-05 16:45:38 +00:00
Rasmus Wriedt Larsen f402475dd3 Python: Fix `globals() == locals()` FP 2021-09-13 20:03:11 +02:00
Rasmus Wriedt Larsen 69fe2a36e5 Python: Add `globals() == locals()` test 2021-09-13 20:02:08 +02:00
Rasmus Wriedt Larsen ba7cdec2ea Python: Add some lines in test file
These are just empty now, such that it's obvious the tests didn't
change.
2021-09-13 20:00:50 +02:00
Rasmus Wriedt Larsen a9694bf0ef Python: Clean whitespace 2021-09-13 19:58:59 +02:00
Rasmus Wriedt Larsen e7fdfd3d3e Python: Move subprocess.call so super-class detection works
This is a temporary fix!

Added minimal working example (MWE) as a regression, so it's easier to fix the
real problem.

only Python 3 is facing the problem -- and without --max-import-depth=1 the test
times out at 10 minutes :O
2020-02-19 14:12:22 +01:00
Rasmus Wriedt Larsen 13568b7b9f Python: Modernise Statements/ queries
Almost. Left out a few things marked with TODO
2020-02-19 14:10:29 +01:00
Rasmus Wriedt Larsen 6e349eb6e7 Python: Make py/side-effect-in-assert handle example
Also removed parantheses
2020-02-19 14:05:55 +01:00
Rasmus Wriedt Larsen ae8dbd81f3 Python: Update test-file for py/redundant-assignment
now the test code can be pasted, and actually works ;)
2020-02-19 14:05:55 +01:00
Taus Brock-Nannestad 9fda4ab480 Python: Fix false positive in `py/non-iterator-in-for-loop`
Should fix #1833, #2137, and #2187.

Internally, comprehensions are (at present) elaborated into local functions and
iterators as described in [PEP-289](https://www.python.org/dev/peps/pep-0289/).
That is, something like:

```
g = (x**2 for x in range(10))
```

becomes something akin to

```
def __gen(exp):
    for x in exp:
        yield x**2
g = __gen(iter(range(10)))
```

In the context of the top-level of a class, this means `__gen` looks as if it is
a method of the class, and in particular `exp` looks like it's the `self`
argument of this method, which leads the points-to analysis to think that `exp`
is an instance of the surrounding class itself.

The fix in this case is pretty simple: we look for occurrences of `exp` (in fact
called `.0` internally -- carefully chosen to _not_ be a valid Python
identifier) and explicitly exclude this parameter from being classified as a
`self` parameter.
2019-11-21 11:49:29 +01:00
Taus Brock-Nannestad 5e62da7690 Python: Do not report unreachable "catch-all" cases in `elif`-chains.
This was brought up on the LGTM.com forums here:
https://discuss.lgtm.com/t/warn-when-always-failing-assert-is-reachable-rather-than-unreachable/2436

Essentially, in a complex chain of `elif` statements, like

```python
if x < 0:
    ...
elif x >= 0:
    ...
else:
    ...
```

the `else` clause is redundant, since the preceding conditions completely
exhaust the possible values for `x` (assuming `x` is an integer). Rather than
promoting the final `elif` clause to an `else` clause, it is common to instead
raise an explicit exception in the `else` clause. During execution, this
exception will never actually be raised, but its presence indicates that the
preceding conditions are intended to cover all possible cases.

I think it's a fair point. This is a clear instance where the alert, even if it
is technically correct, is not useful for the end user.

Also, I decided to make the exclusion fairly restrictive: it only applies if
the unreachable statement is an `assert False, ...` or `raise ...`, and only
if said statement is the first in the `else` block. Any other statements will
still be reported.
2019-10-29 15:30:32 +01:00
Taus Brock-Nannestad 384013e0dc Python: Add tests for reachability when using `nonlocal`. 2019-10-02 17:13:00 +02:00
Taus Brock-Nannestad d336140c19 Python: Modernise the `py/non-iterable-in-for-loop` query.
Also adds a small test case exhibiting the same false positive seen in
ODASA-8042.
2019-09-05 12:24:51 +02:00
Mark Shannon 1c8ce418d9 Python: Add test to confirm #1212 is fixed. 2019-08-28 12:01:04 +01:00
alexey 86ec047be2 Rename files by style guide and change query metadata 2019-05-29 15:35:58 +01:00
alexey 8168c0ee0a Fix typo in test for the query 2019-05-23 15:54:59 +01:00
alexey e214174114 add return-or-yield-outside-of-function Python query 2019-05-22 15:27:32 +01:00
Mark Shannon e9a45268a8 Python: Don't report Python 2 print statements as having no effect. 2019-03-13 10:08:07 +00:00
Mark Shannon 05b69a1c0f QL tests for Python queries and libraries. 2018-11-19 15:15:54 +00:00