Commit Graph

231 Commits

Author SHA1 Message Date
Daniil Kalinin
ba6015d27f PY-64326 implement incremental parsing for PyStatementList PSI elements
These changes make PyStatementList elements (which are function and class bodies, cycle bodies, if-else branches, etc.) lazy-parseable which means they can now be reparsed without reparsing the whole file if changes are happened inside them accepted as safe

The main reason behind these changes is to improve performance

GitOrigin-RevId: 892acbe0c95fde6aec74b7595b0a58f902c426f5
2024-05-07 17:30:41 +00:00
Vladimir Koshelev
8754f98cbe PY-72443 fix module => package mapping for some of the popular ml libs
GitOrigin-RevId: 962d57b87333c8c196dbd52bcfd4b5a41ba7317b
2024-05-06 15:20:45 +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
Mikhail Golubev
5f6848fccb PY-65966 Disable partial tensorflow stubs in Typeshed with a registry flag
Otherwise, incomplete stubs break our custom logic for resolving tensorflow
modules re-exported from its _api.v2 subpackage, such as tensorflow.audio,
tensorflow.image, tensorflow.random, etc.

We did the same for Numpy stubs in the past, enabling them back once they
became mature enough.

GitOrigin-RevId: b1e46067406a592761f56b7d296a287e5282b079
2024-04-23 11:03:04 +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
Petr
4602d09655 PY-61639 Extracted PyHighlightingAnnotator
GitOrigin-RevId: 432bcb87b77fa55f1ccb26000d91ae021cebcc6b
2024-03-27 15:05:16 +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
Petr
6b3d789a4b PY-61639 Client keyword highlighting
GitOrigin-RevId: 5af1268616b174cf1c163d60e8c41c02897ecbf7
2024-03-19 20:04:36 +00:00
lada.gagina
2f4f004d11 [python] requirements.txt: Rename the visitor, remove extra inspection description
GitOrigin-RevId: 17f897c74dee05cf1fdc128d124a8a493586b45e
2024-03-05 15:56:14 +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
Petr
b9167aef8b PY-61639 Move PyPreFormatProcessor to python.syntax.core
GitOrigin-RevId: 30d204206de9e09eae34baf0555fc9be5822ba68
2024-02-16 15:53:21 +00:00
Petr
d7630f0ef5 PY-61639 Move PyTrailingBlankLinesPostFormatProcessor to python.syntax.core
GitOrigin-RevId: a33777ac12163807f1395cbb8b03c58df506c3cf
2024-02-16 15:53:16 +00:00
Petr
2c7f5b4b32 PY-61639 Move PyPreFormatProcessor to python.syntax.core
GitOrigin-RevId: 4832fe901219342bb7f1babf41280830e16fec49
2024-02-16 15:53:11 +00:00
Petr
85c54b3a4c PY-61639 Move PythonFormattingModelBuilder to python.syntax.core
GitOrigin-RevId: bdcbd076cd3c1531204eff35515b44cd0edc9f68
2024-02-16 15:52:22 +00:00
Petr Golubev
25b8ebcf83 PY-61639 Extracted PythonEnterHandler
GitOrigin-RevId: 8fd0c063c917e07c3f1bf98533c3de867f770ee9
2024-02-08 13:58:08 +00:00
Petr Golubev
1a73bd2d21 PY-61639 Extracted PyAstElementGenerator
GitOrigin-RevId: 915c235120b079188d81efaa9ccf9728131fa3df
2024-02-08 13:58:08 +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
Ilya.Kazakevich
b533e29ce0 [python] get rid of classes registered in wrong modules
You must register class in the same v2 module class sits

GitOrigin-RevId: c7fcccd27c2fcaa3d9391d1173f61ad43fe2b076
2024-01-17 04:59:01 +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
Ilya.Kazakevich
7d6afbdf7e Move tensorflow to the correct package as everything must be in com.jetbrains.python in this module
GitOrigin-RevId: e684b59a25303e4ed7f41a109a58bc424a532c1d
2024-01-09 03:00:09 +00:00
Ilya.Kazakevich
fc2c5e4389 Move numpy to the correct package as it sits inside of includable module
GitOrigin-RevId: 3f697f59e60c11b03a1cc04649b864d510310cd3
2024-01-09 03:00:02 +00:00
lada.gagina
75b1ecd244 [python] Cleanup supported/unsupported versions xmls
- Drop support for python 3.5 & 3.6 in compatibility inspection
- Fix and remove some outdated tests
- Remove xmls for long-unsupported python 2.6 & 3.5
- Regenerate versions.xml
- Remove mentions of OS-specific modules

GitOrigin-RevId: 3265dd1de8a4f7a41119e10c95bb705ca5845efe
2023-11-17 18:57:31 +00:00
Daniil Kalinin
646ba00a3d PY-61857 Implement PEP 695 Type Parameter Syntax usage inspection:
Inspection covers such cases:
* Extending typing.Generic in new-style generic classes
* Extending parameterized typing.Protocol in new-style generic classes
* Using generic upper bounds and constraints with type parameters for ParamSpec and TypeVarTuple
* Mixing traditional and new-style type variables
* Using traditional type variables in new-style type aliases

GitOrigin-RevId: 8812959f64d2d87e1b72f713405edb86936220b9
2023-11-06 19:59:18 +00:00
Mikhail Golubev
834084969c PY-40395 Report usages of classes inside type hints in a dedicated group
GitOrigin-RevId: ceceb43cc9c82a4831e5df9790a1689ee792edf4
2023-10-23 23:44:32 +00:00
Andrey.Matveev
c24752ceb1 PY-58752 Impl inspection for check matching override signature
GitOrigin-RevId: 4520138ac657a514b53f2f939521f0336701be46
2023-10-22 10:27:24 +00:00
Mikhail Golubev
a14c9ef92c PY-53105 Support PEP 646 and TypeVarTuples. Take 2.
The introduction of TypeVarTuples and the concept of unpacked tuple types made us
revise all the places where we match sequences of types in type inference.
For instance, when matching type parameters and type arguments for generic
specialization in:

* type hints, i.e. xs: MyGeneric[int, str] = MyGeneric()
* constructor invocations, i.e. xs = MyGeneric[int, str]()
* class declarations, i.e. class MyGeneric(Base[T1, T2, str]): ...
* type alias declarations, i.e. MyAlias: TypeAlias = MyGeneric[T, int]

as well as during type matching of all generic types, both normal non-variadic and
existing "built-in" generic variadics in the type system, namely tuples and
Callables.

Previously, this logic was spread across numerous places in PyTypeChecker and
PyTypingTypeProvider, all with their own subtle differences. The first attempt
of PEP 646 support put all the code for uniform matching of type parameters directly
in PyTypeChecker, significantly complicating its already arcane internals.
I've introduced a unified API for that called PyTypeParameterMapping.
It still retains some of the former quirks in form of its Option flags, controlling
in particular how we handle having some of the expected types unmatched
(imagine expecting MyGeneric[T1, T2, *Ts] and receiving MyGeneric[int]),
but I'm planning to gradually eliminate this conditional logic.

The same class is now also responsible for matching parameter types of callables
that already allowed to fix some of the known problems, such as ignoring their
arity (PY-16994), but I'm going to extract a separate API entity for that, since
matching of callable signatures is a much more complicated task involving
compatibility of different types of parameters (positional-only, keyword-only,
defaults, varargs, etc.).

Another positive side effect of these changes is that substitution of type
parameters during type inference became more consistent, and we no longer lose
useful type information by replacing all unbound type parameters with Any. It's
particularly visible in type checker errors where we stopped dropping unbound type
parameters from messages about mismatched parameter-argument types.

Among other improvements in this changeset are proper scoping for
TypeVarTuples, consistent with other type parameters, and recognizing TypeVarTuples
and unpacked tuples in types of *args parameters in function bodies, e.g.
`*args: *Ts` translates to "args" parameter having the type `tuple[*Ts]`.

Confusing PyNoMatchedType used only for reporting of missing arguments for *args
parameters annotated with unpacked tuples in the type checker inspection, e.g.

def f(*args: *tuple[int, str]): ...
f(42)  # a type checker error about a missing argument for str

was also removed from the type system in favor of a simpler approach with handling
such errors directly in the inspection. We might need such a general type in
the future, but it has to be well thought-through.

GitOrigin-RevId: 63db6202254205863657f014632d141d340fe147
2023-10-20 13:38:06 +00:00
andrey.matveev
a75c569022 PY-53105 Support TypeVarTuple
GitOrigin-RevId: f8160e9d802b09991daa710ed9a20f3e30d455da
2023-10-20 13:38:04 +00:00
Vladimir Koshelev
158bc649f1 [python] implement package name collectors for imports in file and completion
Also, this commit changes the behavior of PyPIPackageUtil, now only one package per name is supported. Motivation:
- it complicates the logic in all usages of the mapping
- There are only 3 cases when it's applicable and in all cases the second package is abandoned.

GitOrigin-RevId: 80fb1e0d28369bdfeb64f6b928ed1b543165d1de
2023-10-13 09:51:16 +00:00
Vladimir Koshelev
29f0eb6c77 [python] extract python parser to a separate module
Merge-request: IJ-MR-116296
Merged-by: Vladimir Koshelev <Vladimir.Koshelev@jetbrains.com>

GitOrigin-RevId: e7559fb3215d757e6273543e4aa27d52df755e63
2023-10-09 11:56:10 +00:00
Louis Vignier
a7d33eaba6 [properties] Cleanup: fix extra space before ellipsis
#IDEA-334322 Fixed

GitOrigin-RevId: 7114856688771756bae7694542abac6e5ad1177d
2023-10-07 10:54:04 +00:00
Mikhail Golubev
37d25ee815 PY-59594 PEP 701: Allow quote-reuse and line breaks inside f-strings. Keep reporting these problems for Python <3.12.
PEP 498 required f-strings to be recognizable by existing tooling, such as syntax highlighters,
by prohibiting re-using quotes of the same kind and having line breaks inside expression fragments.
We used to detect these problems already at the lexer level, correctly replacing violating quotes
with FSTRING_END token, and appending STATEMENT_BREAK tokens to illegal line breaks inside expressions,
depending on the lexer's state. Now, thanks to a general f-string grammar in PEP 701, most of this
bookkeeping could be moved from the lexer to the CompatibilityVisitor (to still be reported
for previous versions of the language and by the compatibility inspection).

Previously forbidden backslashes and line comments are now also detected by the CompatibilityVisitor
instead of the version-agnostic FStringAnnotator.

One side effect of the new grammar is that parser recovery in pre-3.12 version of Python became
slightly worse. For instance, something like `f'{foo'` used to be recognized as an f-string
with an incomplete fragment lacking its closing brace. Now, it's parsed as an incomplete
f-string, lacking its own closing quote, containing an incomplete string literal inside
an incomplete fragment. What's more, parsing of this fragment's expression doesn't terminate
until the end of a file, because STATEMENT_BREAK is never produced by PythonIndentingProcessor
while it's inside an f-string fragment, and every quote is considered a new string literal.

Examples of parsing tests affected by this are:
PythonParsingTest.testFStringFragmentIncompleteTypeConversionBeforeClosingQuote
PythonParsingTest.testFStringIncompleteFragmentWithTypeConversion
PythonParsingTest.testFStringIncompleteFragment

I also had to simplify some scenarios from PythonHighlightingTest, removing snippets
with incomplete fragments or moving such examples to the very end of a file.

It's not clear how to handle these situations not overcomplicating the lexer.

(cherry picked from commit 03ba6d7fba1b45a84aa92221e6a452645a765205)

IJ-MR-115763

GitOrigin-RevId: cd36470d9cae353fe3caeb2d3b628d8743b46cbb
2023-09-29 09:33:42 +00:00
Daniil Kalinin
9249e0a15c PY-61856 PEP 695 Type Parameter Syntax: Code compatibility inspection and unsupported features annotator
GitOrigin-RevId: 164a07daff1059ac1a421e1a883168924f82559e
2023-09-28 15:05:34 +00:00
Daniil Kalinin
8b217ed53a PY-61853 PEP 695 Type Parameter Syntax: Parsing
GitOrigin-RevId: 286b53bb4e69cf1deb58dc75f41652e6a12a3af3
2023-09-15 16:04:41 +00:00
Egor.Eliseev
540f24faa4 PY-34498 Add an inspection for pytest fixture that is not passed to test parameters
Report warning if a fixture is used without being passed to test function parameters or to
`@pytest.mark.usefixtures` decorator.


Co-authored-by: Denis Mashutin <Denis.Mashutin@jetbrains.com>


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

GitOrigin-RevId: 28d0711b99ab7ae180f672306dd4ab8a81f1feec
2023-09-04 09:53:07 +00:00
Olga.Lavrichenko
b554080676 DS-5431 Column names are not at the top of the completion suggestions list in Jupyter notebook
Merge-request: IJ-MR-113147
Merged-by: Olga Lavrichenko <Olga.Lavrichenko@jetbrains.com>

GitOrigin-RevId: 777ade236fcbe9e596cc61cc20cce072f2d3ef97
2023-08-17 12:57:00 +00:00
Sergey Karpov
c0842a6fde [pycharm] Squashed commits. PY-52478 Improve the names of quick fixes for "Unresolved references" and "Non-optimal list declaration"
(cherry picked from commit bce089714657aef8634ffb9c58da57fdb576b297)

IJ-CR-112218

GitOrigin-RevId: 8857c2951e44a1e9d0b54af1eb7c584f64fbc40d
2023-07-31 16:31:00 +00:00
Mikhail Golubev
1a854fceb8 PY-55246 Enable back .pyi stubs bundled with numpy
We turned them off as part of PY-48166. Now these stubs are much more complete
and fix a number of problems with the code insight for the library (PY-35164,
PY-37461, PY-50394, PY-59347, PY-60224), most of which are caused by the lack
of information in skeletons automatically generated for its binary modules or
incorrect type information being extracted from docstrings.

I leave the possibility to disable the stubs for the time being and will remove
the registry option once it become clear that they don't cause serious problems.

GitOrigin-RevId: 0df09ddb8ca40f88b908e19c0f49f5b005abaa58
2023-07-14 14:00:34 +00:00
Mikhail Golubev
d22b8b00b9 [python] Extract a common quick fix for unresolved package problems
GitOrigin-RevId: a1db8823a2fc83424431d975e1820b415895cc7a
2023-07-06 10:41:32 +00:00
Lada Gagina
454b1287ae PY-58857 Infer typing.LiteralString for string literals
GitOrigin-RevId: 27507deabd61faedf7937415016f0f8334e5a418
2023-06-21 16:32:22 +00:00
Daniil Kalinin
157b23ce53 PY-33261 Inlay parameter hints for Python method and function calls
Merge-request: IJ-MR-108471
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: 1d9451020a755c0aaf57c12b16829f8b31291e5d
2023-06-20 05:27:45 +00:00
lada.gagina
e768aa3785 PY-40996 Add ability to collapse and expand python type annotations
"Collapse/Expand Python Type Annotations" actions, an intention and a setting

GitOrigin-RevId: e055538b29b07c1836399f52754b786a15351050
2023-06-16 19:08:16 +00:00
Trinh Anh Ngoc
c9f0c216a0 [PY-56210] Add id for PyModuleNameCompletionContributor
Allow other contributors to take priority over it if needed

closes https://github.com/JetBrains/intellij-community/pull/2197

GitOrigin-RevId: 06e7378ddb47a57dc8e934afcadd7f0d1b88bbb7
2023-06-15 20:21:10 +00:00
Olga.Lavrichenko
b221598456 DS-4113 Columns are duplicated in completion suggestions in python console
GitOrigin-RevId: 527cfd230c94b229ccf2f5d5263ba1171614cabb
2023-05-19 17:53:17 +00:00
Natalia.Murycheva
0d53aa47df DS-4878 Pandas-specific-quick-fix-replace-listdf.col.values-to-df.col.tolist
Add new intention and a corresponding quick fix for the usage pd.Series.values property from pandas library.

^DS-4878 Fixed

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

GitOrigin-RevId: 0c8dc40b09ee2d95ecd8ded532f31f5ef4a7740f
2023-05-13 20:44:29 +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
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
Irina Fediaeva
bb882b63f5 PY-55118: Syntax highlighting for definition signatures in Quick Documentation
GitOrigin-RevId: b8a27a048772a0af7fcc36a9cba0d308e0ace8cc
2023-02-10 22:44:22 +00:00