Commit Graph

1121 Commits

Author SHA1 Message Date
Alex Plate
7b20721031 [Workspace Model] Use set for changelog in WorkspaceModelChangeListener
This is needed for a clearer understanding of the API: there is no ordering of changes in VersionedStorageChange

GitOrigin-RevId: 2a3800e216d81e87e836f8bd19708b5ba74f496a
2023-05-06 09:32:47 +00:00
Alexey Kudravtsev
970ae99e6d use ContainerUtil.createMaybeSingularList() to simplify code
GitOrigin-RevId: 3474c183588944fa16fef901302492bf714aa815
2023-05-04 14:09:30 +00:00
Natalia.Murycheva
10f22bb2e2 DS-4558 Quick fix to split a cell for statement has no effect inspection
Added a new Extension Point for corresponding quick fixes for "Statement without effect inspection." Added QF for Jupyter notebook case and Python file with cells. This QF splits cell just right after the statement without effect

^DS-4558 Fixed

Merge-request: IJ-MR-104455
Merged-by: Natalia Murycheva <natalia.murycheva@jetbrains.com>

GitOrigin-RevId: 7773895cf1ebd6d4e8d56b41e335ec8b97ca5d78
2023-05-03 15:03:06 +00:00
Louis Vignier
1869ec9da6 [codeInspection] Fix python inspection descriptions
GitOrigin-RevId: 56876a5dd073a06c3fcc92f63ed1f5674830bc25
2023-04-28 13:13:25 +00:00
Mikhail Golubev
29bbb0faf6 [python] Get rid of TreeSets in PyNamedTupleInspection
Rely on the fact that PsiScopeProcessor processes class attributes
in the order of their definition.

GitOrigin-RevId: 0b39b0c6002c75d2af3b4988d3aa095823b33cb8
2023-04-26 13:16:47 +00:00
Mikhail Golubev
70fa9400f4 [python] Simplify PyNamedTupleInspection
Got rid of redundant inner classes and fields, removed repeated logic, used
more obvious control flow constructs.

GitOrigin-RevId: a04977afc8a0ceb213380b406e74e37dfc7cd49c
2023-04-26 13:16:47 +00:00
Irina Fediaeva
069ee247c0 PY-45381: Fix false-positive when overriden non-default fields follow defaults defined in parent dataclass
GitOrigin-RevId: ee08f0db368951ea8f02835f1af8c57fae34dabd
2023-04-26 13:16:46 +00:00
Egor.Eliseev
5de3620016 PY-57950 Quick Documentation not working in Python Console if the caret is at the end of the expression
IJ-CR-100091

GitOrigin-RevId: 5f651b03cd0c3f2caa145c2401523301c5f61f56
2023-04-26 10:08:00 +00:00
Daniel Schmidt
8e61858381 PY-57950 - resolve callee for argument list
GitOrigin-RevId: 5b418107c312d9a70110a351a87bb1163e72806f
2023-04-26 10:07:59 +00:00
Irina Fediaeva
3afa041f1b PY-32067: Highlight 'await' outside async functions as errors
GitOrigin-RevId: 9862d18848b3a826ba11e9c0e15e56a2c94bcc9e
2023-04-19 20:42:02 +00:00
Daniel Schmidt
abedaa8420 PY-39352 - use the more accurate term "CapWords" instead of "CamelCase"
closes https://github.com/JetBrains/intellij-community/pull/2403

GitOrigin-RevId: 09122e4c36fc6f40d9b79869152d0fd9f2fdeeda
2023-04-17 14:52:30 +00:00
Daniil Ovchinnikov
6fe5c49599 deprecate com.intellij.reference.SoftReference constructors
GitOrigin-RevId: a723be59b812f71953e79879d7adf09d58a9e935
2023-04-15 00:04:29 +00:00
Dmitrii Gridin
0627d87b40 [python] avoid redundant algorithmic complexity from getLanguageLevelForVirtualFile
^FL-18949

GitOrigin-RevId: 802e02344037d47058a7fcd983fe7902e847156a
2023-04-14 17:53:40 +00:00
lada.gagina
18590c0781 Sync with typeshed @ f611d18f70fd9f20797c832f10bba3bfb9d99e47
[PY-59793](https://youtrack.jetbrains.com/issue/PY-59793/Sync-bundled-typeshed-f611d18f70fd9f20797c832f10bba3bfb9d99e47-sep-22)

GitOrigin-RevId: 9dcaafbd9bf1bc6f077e130042883a7a0436961f
2023-04-14 12:44:45 +00:00
Irina Fediaeva
7379dc43c5 PY-49946: Support 'kw_only' in @dataclass args and dataclasses.field() args
GitOrigin-RevId: fe6f32a2cb8fa65b122968e1e9cf9d2126f92398
2023-04-12 17:59:46 +00:00
Ramazan Dzhekshembaev
1469475419 add template test for fix
GitOrigin-RevId: a192f2b50c5576c87d264bf893b0453fea032e17
2023-04-06 11:45:08 +00:00
Anton Lobov
78c02bc722 FL-10775 [fleet] properly find the enclosing expression
GitOrigin-RevId: 89ac7e992a08cdfea4f53cfee79727f3a041cf4b
2023-03-31 16:34:45 +00:00
Sergey Ignatov
b051bddf6b [fleet] yet another npe in python qf, FL-18078
GitOrigin-RevId: b540d6f6aafb881c1ede60a80c6235d88e52585e
2023-03-30 23:28:26 +00:00
Mikhail Golubev
3c6a3baf1a [python] Fix an error when extracting a part of string with %-style formatting
Namely, if substitution values were passed as non-literal value compatible with
collections.Mapping, use plain string concatenation. The existing condition for
that was wrong.

GitOrigin-RevId: b6e9b9c615d80aa7842f883086b3544e095d5f81
2023-03-29 21:30:27 +00:00
Mikhail Golubev
07a2ea7149 [python] Fix a constant value problem
GitOrigin-RevId: b37f4e32d9ff3a6ecff13c6d0438ff99ca44d26d
2023-03-29 21:30:25 +00:00
Andrey.Matveev
e8615b4f7f PY-59760 Use PyTypeParameterType in PyTypeChecker#isUnknown
GitOrigin-RevId: d07691ae8713621bbca0393ea78a144130eebf1c
2023-03-29 20:28:59 +00:00
Mikhail Golubev
e0d4db03da PY-59727 Infer types from usages only for collections assigned to variables
For everything else, e.g. d['key'] = {'foo': 42}, we cannot track subsequent
modifications of d['key'], such as d['key']['bar'] = 1, anyway. We need
a reference as a subscription operand, or a callee to make sure these mutating
operations are performed on the same value. It doesn't make sense to scan
through an entire containing scope looking for subscription expressions
and calls on such assignments targets.

GitOrigin-RevId: 8ebbcb73e43e5711cbe680da6936f3f1c4e54a55
2023-03-29 09:30:40 +00:00
Mikhail Golubev
a76592e754 PY-59795 PY-59727 Check assignment targets when inferring TypedDicts from dict modifications
Not doing it not only led to incorrect results, but also could cause serious
performance problems as in PY-59727 when we started recursively analyzing
assignments to a parent dict, producing gigantic hierarchies of nested
TypedDict types as a result.

Namely, each type we tried to infer a TypedDict for a dict literal
in the RHS of an assignment to another dict's key, like the following

d['key'] = {...}

we started to analyze all the modifications of "d" all over again, even though
they couldn't affect the type of the assigned literal. Doing that, we eventually
tried to infer the type of this literal again, and the recursion guard in
TypeEvalContext finally set off. But before that, we'd already constructed
a tree of TypedDicts with the depth roughly equal to the number of such
subscripted assignments to "d". For the user's example, such a TypedDict
contained millions of elements completely hanging our inspections.

GitOrigin-RevId: 5a17894d501086ed4d4ec6bdd8a17c1f05dd7bd5
2023-03-29 09:30:38 +00:00
Anton Lobov
a3a8983f13 FL-10775 [fleet] fix python provider (performAction was re-evaluating the expression)
GitOrigin-RevId: 55c117daa97c7c2372eb3889b254fb0a8ccf760f
2023-03-28 14:02:38 +00:00
Tagir Valeev
e4e0e714ce Warnings fixed
GitOrigin-RevId: ff62f8f55b687d3d1974c64f8662be4acd2c6b03
2023-03-21 13:09:27 +00:00
Mikhail Golubev
e0b1364ebd [python] PECS-generify and enforce immutability of PyTupleType
It has revealed a bug (most likely stochastic) with mutating a cached tuple
type in PyCollectionTypeByModificationsProvider.

GitOrigin-RevId: 2e830ae5691acbc4855107d0a18dc81ad43ab3eb
2023-03-20 11:01:51 +00:00
Mikhail Golubev
a183d1fc9e [python] Use PyTypeParameterType for collecting substitutions in PyTypingTypeProvider
Also, PECS-generified the constructor of PyCollectionTypeImpl and enforced its
immutability.

GitOrigin-RevId: 221aae833624dca13f0e3c77bfb468f82d035667
2023-03-20 11:01:46 +00:00
Mikhail Golubev
52b283f78f [python] Make PyDecoratable interface extend PyElement
It's always applied to Python-specific PSI elements. There is no need to do
a separate cast just to access methods of PsiElement.

GitOrigin-RevId: 481577fa8d2092df7884d6e611622f0bbd4d1e54
2023-03-17 21:45:06 +00:00
Mikhail Golubev
b1fd219835 PY-59548 Recognize generic class inheritance through aliases in stubbed files
Namely, evaluate expressions in the list of base classes as regular
type hints in PyTypingTypeProvider. It allowed us to properly consider type
aliases, as previously used PyResolveUtil.resolveQualifiedNameInScope reached
only up to the first type alias not following assignment chains further to
class definitions.
It simultaneously made collecting type substitutions for generic classes simpler
since we don't need to replicate the logic of parsing subscription expressions
in type hints specifically for base class expressions and can instead
retrieve type arguments corresponding to expressions in brackets directly from
PyCollectionType.getElementTypes.

Since we process both subscription expressions and plain qualified names in
the list of base classes uniformly now, evaluating them all as type hints,
PyClassElementType.getSubscriptedSuperClassesStubLike also became obsolete.

GitOrigin-RevId: 8a2a45c1be0259ee62f82595289842f043ae02b2
2023-03-17 21:42:37 +00:00
Tagir Valeev
9e03824935 [python] EA-814012 - NPE: PyBroadExceptionInspection$Visitor.isExceptionUsed
GitOrigin-RevId: 3edf873adb39d53989ec05823908a94016a3dbe6
2023-03-14 20:30:20 +00:00
Mikhail Golubev
d070837f27 PY-38075 Select the first matching overload unless some argument types are unknown
This behavior is similar to how mypy and pyright handle overloads relying on
their definition order, where more specific signatures are supposed to precede
more general ones. The subtle difference is that in case of Any arguments,
pyright tries to find a common supertype for return types of all matching
overloads, mypy just returns Any, and we return a union of their return types.
For the time being, it keeps things simple and matches how we treated ambiguous
signatures before.

To make this work, I've had to revise how we handle name redefinitions in files.
Previously, we processed them in the reversed order to give priority to those
later in a file, which is natural for regular .py files. It doesn't make much
sense for .pyi stubs, though, as it's impossible to redefine a name there and
multiple definitions, e.g. overloads, are supposed to have equal precedence.
Now, we don't reverse the order of name definitions in .pyi stubs at all,
and in .py files we do that preserving the original order of overloads.
A side effect of it is that now we always navigate to the first overload
of a name in a .pyi stub, as opposed to the last, but it only seems more
logical and convenient.

On the other hand, when we handle overloads in .py files, we explicitly
assign to them a lower resolve rate to give precedence to implementations.
The only exception is that when there are no implementations we still want
to prefer the latest overload, so we put it into the results second time
with a higher rate. It messed up overloads order important for type inference,
so I've introduced a dedicated RATE_LIFTED_PY_FILE_OVERLOAD rate for such
results to filter them out later in PyCallExpressionHelper. I've also added
a named RATE_PY_FILE_OVERLOAD rate of other overloads in .py files to make
them more easily distinguishable from other resolve results with a low rate.

GitOrigin-RevId: e921654e47fe1fc5da047950b70775e342996757
2023-03-14 10:56:49 +00:00
Irina Fediaeva
b805ad488d PY-30967: Do not show "missing docstring" in case of inheritance
GitOrigin-RevId: 48b227b0818391034b2d79085862c8a6934f8c66
2023-03-14 00:06:35 +00:00
Valentin Fondaratov
b0409e5725 FL-17880 do not setFormat in PyDocumentationSettings in preview
GitOrigin-RevId: 61ca29a6272e418a230b8aedad18488087db6152
2023-03-13 12:26:06 +00:00
Alexandr Evstigneev
2271eb1907 IDEA-313615 upgrade JFlex to 1.9.1
GitOrigin-RevId: 72933159ba8a1ae68d39a39a52be46214bb497c5
2023-03-11 11:18:03 +00:00
Elizaveta Shashkova
5c58b4abdf PY-58092 SlowOperation: do not show superclasses in import suggestions (and remove parenthesis for functions)
(cherry picked from commit 04ee190f4491ce78e0a53622e75bcaeb41fa8370)

IJ-MR-103609

GitOrigin-RevId: 0b3fc6a73b0f74021d4854fb2816b8de494806b8
2023-03-10 13:14:47 +00:00
Vladislav Rassokhin
6ccf88cac0 [python] Minor improvements in PyTypeParser
Also migrate from PyGenericType to PyTypeVarType

GitOrigin-RevId: 0e0d805e2b3da1e56aafcda774dbf05910963ec8
2023-03-08 19:21:07 +00:00
Mikhail Golubev
4d9e251568 PY-59241 Infer PyParamSpecType with proper scope for P.args/P.kwargs-annotated parameters
Previously, we inferred tuple[Any, ...] for such parameters and then replaced it
with a PyParamSpecType in PyTypeCheckerInspection specifically for its checks.
However, inside the inspection we didn't have enough context information to
properly detect the right type parameter scope.

Now, PyParamSpecType is created for vararg parameters annotated with "P.args" and
"P.kwargs" directly in PyTypingTypeProvider, uniformly with other possible usages
of ParamSpec and with accurate scope checks.

This also changes how we handle unrecognized parameter type hints. Previously,
we returned null for them, delegating to other type providers, which could lead
to subtle bugs. Now, when a type hint is present, but can't be identified,
we return Any, thus ignoring any further sources of type information.
It was triggered in PyProtectedMemberInspectionTest.testMemberResolvedToStub
in particular, where we ignored an annotation containing a broken
forward reference to a containing class, proceeding to a nearby .pyi stub.
This was most likely an honest mistake, so I've updated the test data.

GitOrigin-RevId: 02945e756c5f9a8097360c3bcf3f1c5f267c02e4
2023-03-06 23:32:11 +00:00
Mikhail Golubev
c25b2fec9c PY-59241 Replace instantiations of PyGenericType with PyTypeVarTypeImpl
The rest of the usages will be updated later on not to cause excess conflicts
with a few big features currently being developed.

Also removed a redundant constructor that can be replicated with
toInstance/toClass methods.

GitOrigin-RevId: d9af65d8ac865b1eb822607987f8195809f3ec23
2023-03-06 23:32:09 +00:00
Mikhail Golubev
d638124b28 PY-59241 Make PyParamSpecType extend PyTypeParameterType, implement getScopeOwner()
GitOrigin-RevId: 32898066868edf9bdb65bac75bf1a9cde2fbef13
2023-03-06 23:32:06 +00:00
Mikhail Golubev
ced15334ec PY-59241 Make PySelfType implement PyTypeParameterType
GitOrigin-RevId: 9d1e6cd6486958377dbcbec742c4896829e460f6
2023-03-06 23:32:01 +00:00
Mikhail Golubev
fb5a3a200a PY-59241 Extract PyTypeVarType and PyTypeParameter interfaces, deprecate PyGenericType
Existing usages haven't been updated yet not to hinder the upcoming integration
of TypeVarTuple (PY-53105) and LiteralString (PY-58857) support.

GitOrigin-RevId: 16aafd07edfdc98dee0240dce7cd3383b5eb0b00
2023-03-06 23:31:58 +00:00
Mikhail Golubev
0680fcc498 [python] Simplify a loop in PyProtectedMemberInspection
GitOrigin-RevId: ffc46b67fd4470f34af467d89aada3f41bd7387c
2023-03-06 10:21:42 +00:00
Mikhail Golubev
ea10b75484 PY-56541 Remove creating a nested context to detect the scope owner of a TypeVar
It's difficult to reason about how these should work with caching of
PyTypingTypeProvider.Context in TypeEvalContext.

Additionally, I fixed losing an already found TypeVar scope for "T" when
constructing a PyGenericType for "Type[T]". Previously, we did it all over again
for Type[T] in getTypeForResolvedElement at the moment where the corresponding
TypeVar declaration already wasn't at the top of the type alias stack, so it
started to cause EmptyStack exceptions after this change.

GitOrigin-RevId: b22f2ca0ccd12ad9a21294d6ba23574d839e813b
2023-03-02 18:10:17 +00:00
Mikhail Golubev
628d3e6b2b Get rid of the expression stack in PyTypingTypeProvider.Context
To restore the scope of type variables, it's easier to just pass the
corresponding PyReferenceExpression around. This expression stack didn't work
correctly in case of aliases anyway, as its bottom element pointed to the first
type hint where we started evaluation, not where a TypeVar reference actually
appeared.

GitOrigin-RevId: a887b7dbcd85bd37b029318f746fcaeddb59044c
2023-03-02 18:10:14 +00:00
Mikhail Golubev
0f85b19994 PY-56541 Introduce TypeEvalContext.getProcessingContext()
GitOrigin-RevId: 869b5905d05fb3abfb81233e03ab001b5301a3b6
2023-03-02 18:10:11 +00:00
Mikhail Golubev
f6d7b71285 PY-56541 Preserve PyTypingTypeProvider.Context between calls to the provider
The problem was caused by the recursive alias CoreSchema in pydantic-core, none
of our existing recursive type guards protected against.
Namely, pydantic_core.core_schema.CoreSchema alias referred to a number of
TypedDict declarations, many of which used CoreSchema in their own annotations.
Normally, the guard against recursive type aliases in PyTypingTypeProvider
should have caught that, but PyTypedDictType instances are constructed in
another provider and once we left PyTypingTypeProvider we lost the information
about already traversed type aliases, as this information is not preserved in a
regular TypeEvalContext instances.

The protection against recursive evaluation of types in TypeEvalContext, on the
other hand, did catch that, but because it intercepts recursive inference for
the same PyTypedElement and knows nothing about type aliases, so it happened
only when we tried to evaluate the type for the same TypedDict attribute twice.
Depending on the order of TypedDict references within the union type, for some
of them, it occurred only after we'd already traversed through all remaining
TypedDicts trying to build the union type for CoreSchema again for their
attributes. As a result, the size of the tree of these union types grew
exponentially, reaching 13 million elements and bringing our analysis to
its knees.

Ideally, we should have a single entry point in our API for all the computations
related to type hints that should take care of keeping the information about
type aliases. For now, as a workaround, I store the state of PyTypingTypeProvider
in a thread local cache per TypeEvalContext and restore it if we leave and then
get back to the same provider.

GitOrigin-RevId: 5a9b498fefa7dc275e3c4d7d265bdd07f846ad87
2023-03-02 18:10:08 +00:00
Mikhail Golubev
d63f6e0613 PY-56541 Cache type parameter substitutions per PyClass instance
GitOrigin-RevId: aa1513a6a19c50659140c08e7c1155eeb920a37e
2023-03-02 18:10:06 +00:00
Mikhail Golubev
5a21d82cf6 PY-56541 Cache PyTypedDictType instances per its definition
GitOrigin-RevId: f99ff1f463cb03a6607b35c763b1468eb3cc5480
2023-03-02 18:10:03 +00:00
Mikhail Golubev
b5ebc17d64 PY-56541 Fix .equals for PyTypedDictType instances
Because FieldTypeAndTotality used the default Object#equals, two PyTypedDictType
instances for the same definition were not considered equivalent.

GitOrigin-RevId: a241a5199200d5c54a3ae7121e3a417aa18b4ec8
2023-03-02 18:10:00 +00:00
Mikhail Golubev
562e8b5c32 PY-56541 Shortcut matching a union with a type it already contains
GitOrigin-RevId: 050430c0fd8515a46fc4092fb679a8cacce6dc16
2023-03-02 18:09:57 +00:00