Commit Graph

112 Commits

Author SHA1 Message Date
Andrey Vokin
5b0a0b90ee PY-51687 Ctrl-Click on TypedDict usage jumps to builtins.py instead of the TypedDict declaration in the use code
(cherry picked from commit 72d68f8b3099563f77eae1bfd9ef28b8f479a7cf)

IJ-CR-148264

GitOrigin-RevId: 95c8e88ac6e3aef6a8364c2a841a1a8bce2f4d3d
2024-11-12 21:16:33 +00:00
Andrey Vokin
63487fda41 PY-75580 Experiment with extended completion
GitOrigin-RevId: 8aeb4c123eb6c8eae3255c974d8630a0745df395
2024-10-14 13:15:14 +00:00
Ilia.Kondakov
fe4a6bf3a4 PY-50934 Implement features for ML ordering imports
add new features: info about underscores in path, info about lib location, info about context of original file(extension type, psi parents, size of project),
info about already existing imports from the same library(in this file, in other opened files, in other files in the same directory)

GitOrigin-RevId: ca8206d4d7db6bc79e8f1a78502bf33696a653e9
2024-09-27 10:33:53 +00:00
Mikhail Golubev
1da22d34fd PY-54560 Support PEP-681 dataclass_transform
`dataclass_transform` support posed a number of challenges to the current
AST/PSI stubs separation in our architecture. For the standard "dataclasses"
module and the "attrs" package API, we could rely on well-known names
and defaults to recognize and preserve the information about decorator
arguments and field specifier arguments in PSI stubs. With `dataclass_transform`
however, effectively any decorator call or extending any base class can indicate
using a "magical" API that should generate dataclass-like entities.
At the moment of building PSI stubs we can't be sure, because we can't leave
the boundaries of the current file to resolve these names and determine if these
decorators and base classes are decorated themselves with `dataclass_transform`.

To support that, we instead rely on well-known keyword argument names documented
in the spec, e.g. "kw_only" or "frozen". In other words, whenever we encounter
any decorator call or a superclass list with such keyword arguments, we generate
a `PyDataclassStub` stub for the corresponding class.

The same thing is happening with class attribute initializers, i.e. whenever
we see a function call with argument such as "default" or "kw_only" in their
RHS, we generate a `PyDataclassFieldStub` for the corresponding target expression.
Both of these stub interfaces now can contain null values for the corresponding
properties if they were not specified directly in the class definition.

Finally, for the `dataclass_transform` decorator itself, a new custom decorator stub
was introduced -- `PyDataclassTransformDecoratorStub`, it preserves its keyword
arguments, such as "keyword_only_default" or "frozen_default" controlling
the default properties of generated dataclasses.

Later, when we need concluded information about specific dataclass properties,
e.g. in `PyDataclassTypeProvider` to generate a constructor signature, or in
`PyDataclassInspection`, we try to "resolve" this incomplete information from stubs
into finalized `PyDataclassParameters` and `PyDataclassFieldParameters` that
contain non-null versions of the same fields. The main entry points for that
are `resolveDataclassParameters` and `resolveDataclassFieldParameters`.
These methods additionally handle the situations where decorators, superclass
lists and field specifiers lack any keyword arguments, and thus, there were no
automatically created custom stubs for them.

All the existing usages of `PyDataclassStub` and `PyDataclassFieldStub`
were updated to operate on `PyDataclassParameters` and `PyDataclassFieldParameters`
instead.

Counterparts of the tests on various inspection checks for the standard dataclasses
definitions were added for dataclasses created with `dataclass_transform`, even
though the spec is unclear on some aspects the expected type checker semantics, e.g.
if combining "eq=False" and "order=True" or specifying both "default" and
"default_factory" for a field should be reported.
I tried to follow common sense when enabling existing checks for such arbitrary
user-defined dataclass APIs.

GitOrigin-RevId: 4180a1e32b5e4025fc4e3ed49bb8d67af0d60e66
2024-09-09 11:34:15 +00:00
Petr
5d2d6cc722 PY-23067 Pycharm not picking function metadata from functools.wraps with methods
GitOrigin-RevId: d95c1a8f64a6e58d1a6c6c65866b6ab08aaf71b3
2024-08-28 20:02:44 +00:00
Daniil Kalinin
26124892cc PY-75416 disable reparseable statement lists as a workaround
GitOrigin-RevId: d8a5d80fff3886c4f864b2ec82ca8fdf38a9f2b8
2024-08-23 13:54:11 +00:00
Gleb Marin
dc3c5730ea JBAI-5408 Release ML Imports Ranking in 2024.3
[ml tools] Fix build issue

[ml tools] Fix build issue

[ml tools] Fix build issue

[ml tools] Replace task object with service

[ml tools] Fix rebase issues

Add session duration metric

[ml imports ranking] Log fully only during EAP

[ml imports ranking] Set up FUS logs

[ml tools] Add dependency on ml api library


Merge-request: IJ-MR-142857
Merged-by: Gleb Marin <Gleb.Marin@jetbrains.com>

GitOrigin-RevId: 69be00b4b8f38ec71208c3b17cd6566a34508859
2024-08-20 06:16:36 +00:00
Vladimir Koshelev
ec8c3a8aa3 [pycharm] remdev: migrate PyCharm Frontend launcher to v2 modules
GitOrigin-RevId: e2c62c23bd0a22c742a46177c1a1ad4c4b5b95d0
2024-07-24 13:13:53 +00:00
Vladimir Koshelev
c559ffab2b [pycharm] change the order of extended completion contributors to last, so they cannot pollute other stages.
GitOrigin-RevId: 675ead60c308a41142cc0abc1015d2aa50178e02
2024-07-22 12:26:17 +00:00
Daniil Kalinin
e9a6246df3 PY-72185 Implement incremental parsing for PSI leaves for Python
Merge-request: IJ-MR-138193
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: 7d004677a5b7a4637ea956f13ed85abc0d88604e
2024-07-17 12:15:36 +00:00
Petr
5054f4a9b5 [python] Do not store unused decorator arguments in stubs
GitOrigin-RevId: d1a5f63dbed11a4f373d1d7936700af3bc74f70f
2024-07-02 14:04:36 +00:00
Egor.Eliseev
58d8eddeb8 PY-73525 Split HelpersLocator into Community/Pro versions
Merge-request: IJ-MR-138058
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: cd82bc44337e7fdd182262c44ea5ca29e1804ad2
2024-07-02 11:43:46 +00:00
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
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
6b3d789a4b PY-61639 Client keyword highlighting
GitOrigin-RevId: 5af1268616b174cf1c163d60e8c41c02897ecbf7
2024-03-19 20:04:36 +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
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
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
Andrey.Matveev
c24752ceb1 PY-58752 Impl inspection for check matching override signature
GitOrigin-RevId: 4520138ac657a514b53f2f939521f0336701be46
2023-10-22 10:27:24 +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
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
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
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
Petr Golubev
21b7c85809 deduplicate enable.numpy.pyi.stubs registry key registration
GitOrigin-RevId: 982b0b9b177839941a24d581f0587bcd65a5b8d8
2022-11-03 20:26:19 +00:00
Petr Golubev
9862779c8a move PyImportOptimizer registration to PythonPsiImpl.xml
GitOrigin-RevId: c85bf8ddc9dad1fdfcdc03d26aa391b162c97587
2022-11-03 20:26:14 +00:00
Petr Golubev
b461792bc2 register PythonCommenter in the module where it's defined (python.psi.impl)
GitOrigin-RevId: b6c84e51058da5a78b9ae8270b682006b98e1950
2022-11-03 20:26:01 +00:00
Petr Golubev
68f080743c move python formatter extensions to python.psi.impl module
GitOrigin-RevId: 452346cbd12e9c21c636dc8dbcab9a29813bc67b
2022-11-03 14:27:33 +00:00
Mikhail Golubev
59e79c3c7c PY-54503 Provide the result type for Enum[...].value and Enum(...).value
Precise types can be inferred only over AST if it's accessible.

I had to move PyStdlibTypeProvider higher in the provider's hierarchy
so that it could override types coming from Typeshed, otherwise we
infer enum.property type for the "value" attribute.

GitOrigin-RevId: 8727e080cfc06d0edda13eccfd601601dc661da9
2022-09-02 20:51:03 +00:00
Daniil Kalinin
44d07d2450 PY-20811 Support for typing.ClassVar type annotations (PEP 526)
* Dedicated inspections for `ClassVar` variables in variable declarations, variable reassignments, function parameters, local and return variables
* Types of `ClassVar` variables now resolves correctly
* Tests for `ClassVar` inspections

GitOrigin-RevId: 0fd0ef0126ba2c2801ef82bcbeca4ea9b0c48c73
2022-05-24 20:12:55 +00:00
Mikhail Golubev
ff82f4e058 PY-47254 Don't duplicate already imported module names in completion
By running the completion contributor for non-imported modules after everything
else, including the LegacyCompletionContributor offering names present in
the scope, and filtering out duplicate variants.

GitOrigin-RevId: 98982b2c33d1fc11d70b144de556a6825bd3febc
2022-02-23 11:55:12 +00:00
Lada Gagina
c7d12e929d PY-40007 PY-41546 Add completion for keys of dict literals marked as TypedDicts
- in call expressions
- in assignment statements
- in return statements

GitOrigin-RevId: aea2063f7cd7ffc68903c79fa16a25fdf4ff0f8f
2022-02-21 21:13:02 +00:00
Dmitry Trofimov
f35438983c CodeServer: support Python inline variable and inline method refactorings
Also decouple BaseRefacgoringProcessor from UI and split usageView into api and impl parts

GitOrigin-RevId: c4c6d9011726d93f0ee6ab4677f7a105c28ec108
2022-02-08 13:31:12 +00:00
Alexander Bozhnyuk
82a71bcc5c DS-1131 Moving to intellij.python.psi.impl and writing tests.
(cherry picked from commit 28cbf907a7be647fb7fbb4b7fdf822ce36303283)

IJ-MR-17101

GitOrigin-RevId: 70cbab8656c0c9d81e8cf870b699a49c8b12b74e
2021-12-02 21:13:07 +00:00
Aleksei Kniazev
f8c2ad4f8a arguments literals are now stored in python decorator stub (PY-50382)
this makes accessing decorator arguments possible without needing to parse the file again

(cherry picked from commit a9854dbf181f3c7bf488d6ecc18205bb29df2422)

IJ-MR-15304

GitOrigin-RevId: 1031d888a4a08a706c4fa9e2dc48e2f97462c95e
2021-10-18 20:55:54 +00:00
Mikhail Golubev
1421975c96 PY-48012 Resolve and complete attributes in PEP 634 class patterns
Both are implemented other the type of the corresponding class.
References resolve to any readable attribute of a class, however
some obviously wrong variants such as special "dunder" attributes
and methods are intentionally excluded from completion suggestions.

GitOrigin-RevId: 5edac14f47cba39840b15b0dd7f21e2e46077261
2021-10-15 17:36:56 +00:00