Commit Graph

4506 Commits

Author SHA1 Message Date
Petr
abfb927619 [python] PyAssignmentStatementImpl.getTargetsToValuesMapping() Unpack nested tuples as specified in javadoc
GitOrigin-RevId: e0d4c13cadfa11d85ba3ddeba17e3c4cdda0a46d
2024-05-15 00:01:20 +00:00
Petr
b9d89b367a [python] PyAssignmentStatementImpl.getTargetsToValuesMapping() Handle nested parenthesis
GitOrigin-RevId: 6431171bee6624e0256d08fd5e1eddfb82132ccb
2024-05-15 00:01:20 +00:00
Petr
c015ff5cbf PY-55044 TypedDict **kwargs typing
GitOrigin-RevId: 5dff382b321ac166ed4b8cf90e431ea719995608
2024-05-14 23:49:38 +00:00
Petr
aefaeaa52a PY-54151 TypedDict completion at callee does not work for methods
GitOrigin-RevId: 5a037490d8c24ccdd354e8396540a21294148a7e
2024-05-14 22:52:52 +00:00
Petr
feb3bdc4c2 PY-52502 Duplicate completion variants when local variable is used as map key
GitOrigin-RevId: 463225922b2f0201b5d1ed2749f4175a77fd543f
2024-05-14 01:09:52 +00:00
Petr
7965dde4a4 PY-56004 Completion for expected literal types in assignments
GitOrigin-RevId: 06cacc62e068d902b174e5208837959cbd92ed88
2024-05-13 14:59:57 +00:00
Daniil Kalinin
19a4b1d01c PY-64326 tests for incremental parsing of PyStatementList
GitOrigin-RevId: 83e5343e9a164d92f8a5acf43b9ef0790e4a5ce3
2024-05-07 17:30:41 +00:00
Mikhail Golubev
fcf665e761 PY-64304 EA-247016 Report illegal usages of "await" expressions even if there is no operand
In other words, in a statement like "await = 42" there are now both a warning about
the missing operand and a warning that an await expression cannot be used as
an assignment target. This behavior is consistent with other expressions where
additional parsing errors are not special-cased.

GitOrigin-RevId: 37a68eacc7ec042435c185f9ddd8bc2eea42b40f
2024-04-24 09:03:57 +00:00
Mikhail Golubev
b9d7fee816 PY-64304 EA-247016 Don't report illegal "await" expressions used as assignment targets during parsing
Instead, parse them as usual and later report in the dedicated AssignTargetAnnotator
and TypeAnnotationTargetAnnotator. This way, a PsiError element appearing in the PSI
tree of a type declaration statement doesn't cause PyAstTypeDeclarationStatement.getTarget
nullability contract violation.

GitOrigin-RevId: a3e90088cfac7938c398d4d293a72dbd127a2cd0
2024-04-24 09:03:53 +00:00
Petr
e01b0b6beb PY-40480 Completion for argument passed to parameter hinted as Literal
GitOrigin-RevId: 462b03dc35eef70bc873b568cae239d40f1d4974
2024-04-18 20:55:14 +00:00
Egor.Eliseev
9bf5511829 PY-35986 Allow a user to run doctests with pytest
Fix rerunning failed tests for all Doctest.
Do 'Doctest via pytest' option be available not only if a file/fun/class starts with `test_`.


Merge-request: IJ-MR-131237
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: c1e1fda5f66d1e213f34a057175d8e8986a46647
2024-04-13 17:27:10 +00:00
Egor.Eliseev
f48b41f61f PY-35986 Allow a user to run doctests with pytest
Run Doctest via pytest configuration if `pytest` is installed and selected in settings


Merge-request: IJ-MR-130194
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: 4c97411c3da69249e6b9ad886bcbd9a206db744b
2024-04-05 10:15:58 +00:00
Petr
0b75360e40 [python] Improve test coverage of ImportToImportFromIntention
GitOrigin-RevId: 5c98b2124a35b66132b007c2c60236df90b5adff
2024-04-03 21:12:18 +00:00
Petr
4e2f6f2685 PY-28076 Type of assignment target in parentheses is not inferred
GitOrigin-RevId: 457adb65fea311a169ae8fd4ca78a6915518b378
2024-04-02 19:04:20 +00:00
Mikhail Golubev
5b9b9f8fb8 [python] Improve test coverage of ImportToImportFromIntention
GitOrigin-RevId: 59b2ebdfe4a8c9bbaf264f0db8b45a5af2b4533a
2024-04-02 18:57:35 +00:00
Mikhail Golubev
cef42660a3 PY-17627 PY-17733 Resolve class attributes defined in @classmethods
The logic is similar to that for instance attributes. Top-level class
attributes and methods defined in the class body get the precedence,
followed by class attributes defined with assignments in @classmethods
unless the latter would resolve to the same assignments as in

cls.attr = cls.attr + 1

finally, we scan through all other class methods resolving the name
to the first definition inside one of them.

So far, I intentionally didn't expose such attributes in findClassAttribute()
or getClassAttributes() because users of these methods assume that
this API considers only attributes defined immediately in the class body.
Adding extra definitions from class methods might break these usages.

I had to update the inspection about typing.Final, because it relied
on the fact that resolve() on assignment targets on class objects can
lead only to those top-level class attributes, where type hints are normally
located, but now it can lead to assignments to a qualified attribute inside
a containing class method.

GitOrigin-RevId: 0ca5bdaa4efca127ac187e822a49df6795e1028a
2024-03-28 12:17:37 +00:00
Petr Golubev
6a9ce08850 PY-45863 Suggest ImportToImportFromIntention on usages of a name
IJ-CR-121086

GitOrigin-RevId: f46dcf05acb37633bf19d20c91524b9be604723e
2024-03-25 17:55:17 +00:00
Sergey Karpov
fc1db76c4d [pycharm] PY-40180. Gave the test a better name, added a comment with issue ID.
(cherry picked from commit 908a293fa325205be5fc902d788a26b4ed4013b2)

IJ-CR-124368

GitOrigin-RevId: d95a4345437e9d9f8d98def50fec2338b0a7aabc
2024-03-07 12:55:53 +00:00
Sergey Karpov
6ae3e4f160 [pycharm] PY-40180. Renamed the test to reflect the latest LanguageLevel usage.
(cherry picked from commit 3dcc9144326ad66284b0ac250feb6433848d8b28)

IJ-CR-124368

GitOrigin-RevId: 4b33d1ef38e0180bd0b4080647718f880c127802
2024-03-07 12:55:48 +00:00
Sergey Karpov
e371768835 [pycharm] PY-40180. Moved the check inside checkReturnValueAllowed. Added a regression test.
(cherry picked from commit 0367ac9bba083eb46f5759f7fa102cf1545215be)

IJ-CR-124368

GitOrigin-RevId: 0998aaaa50d2d8b6efc49295b22c2245f5477878
2024-03-07 12:55:42 +00:00
Egor.Eliseev
31ede1b27d PY-34498 Add an inspection for pytest fixture that is not passed to test parameters
Fix incorrect fixtures searching in imports. Add test that inspection registers problem only for PyTestFixture.

GitOrigin-RevId: de029bb401689f0218e6fce04e64e738a8051fae
2024-03-05 14:01:54 +00:00
lada.gagina
92e8282dea [python] requirements.txt: Add tests for missing packages inspection (PY-65403)
GitOrigin-RevId: 5183d3b00b640510325c96a6c996cb308fe5b188
2024-02-26 03:26:38 +00:00
lada.gagina
e97eeace5c [python] requirements.txt: Add an in-place inspection for not installed packages (PY-65403)
GitOrigin-RevId: 29d5b17ce5946c807afa635ac11ea9bdaf200999
2024-02-26 03:26:30 +00:00
Alexey Kudravtsev
dfc5db43aa optimization: filter inspection by language more correct in tests
Provide correct EP for inspection tools even with inconsistent tool.getShortName() and shortName="" in plugin.xml.
That allows obtaining correct tool.getLanguage(), and avoid running irrelevant inspections.
E.g. CheckDtdRef inspection doesn't run in java-only tests anymore.

GitOrigin-RevId: 188e9d55686ca084611c5c89cb899874dd078010
2024-02-25 04:22:20 +01:00
Mikhail Golubev
7320815ad2 PY-65385 Retain unbound ParamSpecs as-is during type parameter substitution
The original problem with @contextlib.asynccontextmanager was due to a bug
in PyTypeChecker.substitute introduced in the TypeVarTuple support. Namely,
we started to substitute unmatched ParamSpec types with null, effectively
replacing them in a callable signature with a single parameter of type Any.
Then the special logic in PyCallExpressionHelper.mapArguments that treated
unmatched ParamSpecs as "catch-all" varargs stopped working, and we started
to highlight all extra arguments in the substituted callable invocations.

In other words, binding type parameters from decorator targets, e.g.
ParamSpecs or function return types, never worked because we can't resolve
functions passed as decorator arguments in "de-sugared" expression fragments
in the codeAnalysis context, i.e. when we replace

```
@deco
def f(x: int, y: str): ...
```

with `deco(f)` and then try to infer its type in PyDecoratedFunctionTypeProvider,
but we didn't report it thanks to that special-casing of unmatched ParamSpecs
(other type parameters replaced by Any don't trigger such warnings).

Ideally, we should start resolving references in arguments of function calls
in such virtual expression fragments in some stub-safe manner instead of relying
on this fallback logic. In the general case, however, complete stub-safe inference
for decorators is a hard problem because arbitrary expressions can affect types of
their return type, .e.g.

```
def deco(result: T) -> Callable[[Callable[P, Any]], Callable[P, T]]: ...

@deco(arbitrary_call().foo + 42)  # how to handle this without unstubbing?
def f(x: int, y: str): ...
```

GitOrigin-RevId: adeb625611a3ebb7d5db523df00388d619323545
2024-02-19 16:29:50 +00:00
Artem Mukhin
4c5a6ccc13 [Grazie] Hotfix failing spellchecker tests
https://jetbrains.team/p/ij/reviews/126070/timeline

GitOrigin-RevId: 185a4e392e2d09ccdab5c515ca32895d56f3d77b
2024-02-17 02:46:52 +00:00
Egor.Eliseev
5ef4bd59e7 PY-30279, PY-40318 Add correct type resolve for async and iterated fixtures
Merge-request: IJ-MR-108198
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: dfd6501f64be944bff21621bce6ef45218912337
2024-02-13 20:54:32 +00:00
Alexey Kudravtsev
394e5c640a IDEA-321013 Outdated HighlightInfo's should be removed as soon as the relevant annotator or inspection finishes
Rework annotators engine to make annotators run in parallel, each on all relevant PSI elements in their own order (makes fast annotators complete faster to allow them to remove outdated highlighters faster).
For that, for each annotator (in parallel):
- create its own AnnotationHolder
- rearrange its PSI elements in "time to first diagnostic in previous run" order, to reduce latency.
- run annotator on these PSI elements sequentially
- as soon as annotator produces info/fails to produce the same info from the previous run, update the corresponding range highlighters
Pleas note, there's no more contract "Do not call annotators for parent PSI if some (maybe completely unrelated) annotator/highlight visitor produced error for some PSI element".
Fix highlighting tests, the majority of which relied on annotator order, or implicit contract above.
Fix a bunch of annotators which tried to double-visit some PSI elements to fight the contract above.

GitOrigin-RevId: 74f727fc6d3be3f500cdbb0f26e7d0daf1ffe7ff
2024-02-12 18:52:52 +00:00
Gregory.Shrago
f90dab5aae make EditorTestFixture.type work as in production
Perform real shortcut processing as in production environment.
Must not be called in WA due to that.

GitOrigin-RevId: faa0302c4cd7460f08792e6170ae027cbd415de4
2024-02-09 21:23:08 +00:00
Mikhail Golubev
454deac682 [python] Fix PyStringConcatenationToFormatIntention for enclosing string concatenations
Noticed in IJ-CR-123777.

GitOrigin-RevId: f32832bca10e805fc609babf81382709d58fc480
2024-02-07 17:34:49 +00:00
Mikhail Golubev
b55fd53258 PY-35627 Make Python formatter always add a line break after a decorator list
For regular non-async functions, it already worked thanks to PyTokenSeparatorGenerator.

GitOrigin-RevId: b60dba7b34710cad7dc46ad6f943b3944fc00c42
2024-02-07 17:34:28 +00:00
lada.gagina
e7a2d7c816 [python] Add tests for poetry dependencies completion
GitOrigin-RevId: 193423fca2e21d9e3d7620de9ca14580cd3a512c
2024-01-24 19:42:07 +00:00
Daniil Kalinin
c79da2708c PY-64074 Add Quick Documentation for type parameters and type alias statements
Merge-request: IJ-MR-119974
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: fa0c57b3005b31d892a394b3a5f595ac10135a71
2024-01-23 09:50:49 +00:00
Petr Golubev
05484d8f97 PY-53120 "Add method" action does not create async def
GitOrigin-RevId: 8b2286a3f50d7b0d00ebbb0befc9811a80f7b304
2024-01-19 20:06:59 +00:00
Mikhail Golubev
f9bb539137 [python] Speed up and extend PyVariableAnnotator
Traversing through all children of a PyFunction looking for nested functions,
possibly declaring a nonlocal or global variable, and doing that for every
target expression or a reference to one, is both inefficient and seemingly
hardly needed. For a name being local means that it cannot be accessed
outside the scope of the corresponding function. Updating this variable from
some inner helper function doesn't violate this property. In Python, one
has to explicitly mark a name from an enclosing scope as nonlocal or global to
be able to assign to it within a function. It seems enough (and less surprising)
to rely on this information to distinguish between local variables and everything
else.

All in all, if some local variable is accessed as a nonlocal name in an inner
function, it's now still highlighted as local in the function that defines
it (previously it wasn't), but it is not in the function declaring it as
nonlocal (same as before).

Additionally, we now uniformly highlight as local variables "for" and "with"
statement targets, targets of assignment expressions, names bound in patterns,
and variables in assignments with unpacking (previously it was done only for
trivial assignments).

GitOrigin-RevId: 04c07ae6814a6b531911b3d87a3a26191c934962
2024-01-12 11:52:08 +00:00
Andrey Lisin
1199e0bdaa PY-36882 Fix debugger not working properly with joblib.Parallel when using loky backend
GitOrigin-RevId: 392e04e2e10ae404caf8c561a7c951e7eaea3c9c
2024-01-11 18:52:11 +00:00
Mikhail Golubev
fa168f4a00 PY-36444 Remove @contextlib.contextmanager from PyKnownDecoratorUtil.KnownDecorator
This decorator is fully type hinted in Typeshed, so, with the changes introduced
for PY-60104, it's no longer necessary to special-case it anywhere.
PyDecoratedFunctionTypeProvider can infer the correct type after application
of this decorator to a generator function just as for any other typed decorator.

The original problem was caused by the fact that PyDecoratedFunctionTypeProvider
didn't process declarations having any decorator listed in the KnownDecorator enum,
as presumably all of them were too "magical" to analyze.

Co-authored-by: Daniil Kalinin <daniil.kalinin@jetbrains.com>

GitOrigin-RevId: 53b277803a1eb42784131d0dae5bb7ace173c017
2024-01-09 20:49:13 +00:00
Mikhail Golubev
9300fe8c45 PY-60104 Clean up in tests about type inference for decorators
Removed a number of tests in Py3TypeTest duplicating those of PyDecoratedFunctionTypeProviderTest.

Removed the tests about PY-23067 in Py3ArgumentListInspectionTest and Py3CompletionTest because
this issue was actually not addressed in 05e8ed4df0c7faa24bd972e1b422f664d708b510, and the behavior
some of them assert is not what users wanted.

More consistent naming of tests in PyDecoratedFunctionTypeProviderTest and PyParameterInfoTest.
Removed there excess tests too similar to others or checking scenarios not relevant to
the current approach to type inference for decorators, e.g. presense of @functools.wraps and
alternatives inside decorators — we don't even analyze their bodies anymore.

Add a few extra tests illustrating problems with the current approach:
- testNotAnnotatedDecoratorChangingFunctionSignatureIsIgnored
- testInStackOfDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testInStackOfImportedDecoratorsChangingFunctionSignatureOnlyAnnotatedAreConsidered
- testNotAnnotatedDecoratorRetainsParametersOfOriginalFunctionEvenIfItChangesItsSignature

GitOrigin-RevId: 0bf5070fc523b88dcc9d3009786dd028bdfa0feb
2024-01-09 20:49:13 +00:00
Mikhail Golubev
3079150697 PY-60104 Don't try to infer side effects of not type hinted decorators
Assume that such decorators as well as "well-known" decorators, which we special-case,
don't change signatures of decorated functions and classes.

This change effectively stops the long-standing policy of safe-listing a few recognized
"well-known" decorators and assuming everything else can change a definition in any
way. This approach doesn't apply well to the current state of the Python world, where most
of the common side effects of decorators, such as adding new parameters, can be expressed
in type hints.

In 2021.1 we added PyDecoratedFunctionTypeProvider that was able to infer a return type of
decorator over its body, as for any other function, and then correctly apply this information
to a decorated definition. It led to a number of problems.

First of all, depending on whether TypeEvalContext allowed us to access AST of a decorator's
body, we inferred different signatures for functions decorated with an imported decorator in
inspections and in user-initiated actions, such as Parameter Info.

Secondly, we started inferring useless `(*args, **kwargs)` signatures in case of decorators
defined following the common pattern of returning a wrapper function accepting arbitrary
parameters and itself decorated with @functools.wraps (PY-48338). In some sense, our code
analysis was "too smart" in its type inference in this case.

Lastly, we diluted the return types of functions decorated with unknown decorators, even
fully typed, by uniting these types with Any (so-called "weak" types). This logic
existed before PyDecoratedFunctionTypeProvider, but it became more problematic now
than we were able to propagate this artificial union through generic decorators.

This change in behavior might lead to some false positives for untyped Python code
with non-pure decorators. However, given that other type checkers are also likely to hit these
problems, there is now a stronger incentive to add type hints for such problematic APIs.
In the worst case, we can special-case some heavily requested decorators as we did before.

GitOrigin-RevId: db11fb3573bda5da155cb921a30adc31d5c841e2
2024-01-09 20:49:13 +00:00
andrey.matveev
52f21cc60d PY-48338 PY-60104 Make decorators pure functions if not annotated
GitOrigin-RevId: fed5c22c9114a5dcfb882be367c570baf8ba3e5a
2024-01-09 20:49:13 +00:00
Andrey Lisin
d51a42a60f PY-65353 Add test
GitOrigin-RevId: 9e8beb9b56fae71040e312ab92f6d09e56f6395b
2024-01-09 15:01:02 +00:00
lada.gagina
e5166b993e [python] Inject requirements language into pyproject.toml (PY-42296, PY-54440)
GitOrigin-RevId: 196f56270d0a102a074872871898d640d77b2918
2024-01-08 16:36:32 +00:00
Andrey Lisin
fa03d3e322 PY-37366 Add test
GitOrigin-RevId: c5ca2bfe4cd9a8c9e30deccd5658a71a317e9b23
2024-01-04 18:55:51 +00:00
Egor.Eliseev
e9802d2cb8 PY-62172 Add support for imported using wildcard pytest fixture resolving
Merge-request: IJ-MR-122222
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: f6baf79341bb54c28b2ef6f3faaafa4385266e05
2023-12-14 13:39:07 +00:00
Egor.Eliseev
0aecae551e PY-62419 Pytest fixtures from pytest_plugins are not resolved
Add fixtures searching in `pytest_plugins` statement from `conftest.py`
Add tests


Merge-request: IJ-MR-121756
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: 673ad9a614dba84ffdf87398f908a54af02be81f
2023-12-08 10:44:56 +00:00
Mikhail Golubev
44826d3452 PY-64481 Select __iter__ overload for a for loop/comprehension target matching "self" type
GitOrigin-RevId: 7f3cbdc1d3a6a1fb633d2944567a968b88bfaacd
2023-12-05 17:41:30 +00:00
Petr Golubev
d884d84520 PY-40923 Create function intention does not recognized async invocations
GitOrigin-RevId: d1c1c2891ce66c3d2ae7faafc6683e40d772304e
2023-12-05 13:31:18 +00:00
Daniil Kalinin
99bca18eb1 PY-63856 Add info about TypeVar bounds into the inspection message about unmatched types in PyTypeCheckerInspection.java
Merge-request: IJ-MR-120117
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: fdf3c6fd734f69f82595bb51ce5badc437ca5045
2023-11-28 14:51:31 +00:00
Daniil Kalinin
409ee5968e PY-61858 PEP 695 Type Parameter Syntax: Add Language injections inside quoted forward references
GitOrigin-RevId: f38d5d5d3ae9529e2ffb8ddd252f399fb6cea7bd
2023-11-27 12:16:54 +00:00
lada.gagina
e51528cc47 [python] Add tests for requirements.txt completion for package names and versions
GitOrigin-RevId: 8fc3931d8c3e022264253d8bb9bc0d43a3b6f557
2023-11-23 23:18:30 +00:00