Commit Graph

4536 Commits

Author SHA1 Message Date
Ilya.Kazakevich
e75a7f2f83 Python tests: migrate tox 37->39 (37 is outdated)
GitOrigin-RevId: 8592221541a2a7512d559184bd352dabef5b657c
2024-07-31 10:18:57 +00:00
Ilya.Kazakevich
ccd804fe9c Python tests: migrate tox 37->39 (37 is outdated)
GitOrigin-RevId: 1d8588f3785940c1cbe4036c8a475853f19a79c5
2024-07-31 08:20:14 +00:00
Petr
93b9066edf PY-34617 Support version check
GitOrigin-RevId: 3318ff79cdcc5ba0ce5e4feb65abad5ad0f4acfa
2024-07-28 00:24:15 +00:00
Egor Eliseev
994775243f PY-71926 Refine test detection criteria
Add a new setting Python Integrated Tools: Detect tests in Jupyter Notebooks.
Exclude Jupyter Notebook files from the scope for test detection by default.
Add tests


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

GitOrigin-RevId: 0bee082bde4fa608cb1907b8fbd64b97bb9755a0
2024-07-26 17:24:30 +00:00
Petr
5470f70382 PY-73886 PyArgumentListInspection causes file parsing
GitOrigin-RevId: 8fa6b52a2ac5d28e7148c3e10445ee61fef6c89b
2024-07-25 01:35:16 +00:00
Mikhail Golubev
f392777e01 PY-44858 Create regular packages in refactorings initiated from top-level files in source/content roots
Otherwise, if someone wants to move a definition/extract a superclass from there to
a brand-new package, e.g. from main.py to pkg/mod.py, a namespace "pkg" package will
be created.

Restore the original behavior of PyExtractSuperclassTest.testMultifileNew: the origin
file was inside a regular project root without __init__.py alongside.

GitOrigin-RevId: 750414b18582740076c14bfcfd07fa38992b4428
2024-07-24 16:18:40 +00:00
Mikhail Golubev
1c026ac470 PY-44858 Make multifile scenarios comparing directory content in PyExtractSuperclassTests more uniform
Now they all just compare the resulting test project content with an explicit "after" directory
instead of checking individual files in the test code.

GitOrigin-RevId: cff00d0a6b8ea4547b719997716e95a3f7c62cc9
2024-07-24 16:18:40 +00:00
maxle
90bbc21f3f PY-44858 Move and other refactorings don't introduce __init__.py inside namespace packages
Namely, Move Module Members, Extract Superclass and Make Local Function Top-Level were
all affected by this.
Now we check if the refactoring origin is inside a namespace package to decide whether
__init__.py should be generated for target directories.

Co-authored-by: Kamalia <alishevakamalia@gmail.com>
Co-authored-by: Maksim.Levitskii <maksim.levitskii@jetbrains.com>

GitOrigin-RevId: b0b3420c5ec8d1f7d3000d8834211631690a0c42
2024-07-24 16:18:40 +00:00
Andrey Vokin
e6c66dfd5e PY-74012 Deprecation decorator stub resolves during indexing
Avoid using resolve when calculating deprecation messages

GitOrigin-RevId: 813849bdaeb3819b445db600fc0efbcb014ed5c9
2024-07-19 19:18:54 +00:00
chbndrhnns
c274285cae PY-66043: Resolve module references in PYTEST_PLUGINS
close #2814


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

GitOrigin-RevId: 4a7d46178ceedc283345980f118fbe607d84e685
2024-07-17 15:38:34 +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
Vladimir Koshelev
82e8947e95 [pycharm] move type guards from control flow to PyDefUse stage
GitOrigin-RevId: e66971e619978ad179bb49a15820a7482b27df7c
2024-07-15 18:43:02 +00:00
Vladimir Koshelev
582edda2e8 [pycharm] fix control flow tests after adding CallInstruction
GitOrigin-RevId: 1878a3211a07b216a64df3efa6ac7cb1c94fd246
2024-07-10 14:22:00 +00:00
Vladimir Koshelev
2625d2472b [pycharm] remove NoReturn logic from control flow builder
GitOrigin-RevId: 85ba28fd8b86fe0b6337703798a0b869bb793e88
2024-07-10 14:22:00 +00:00
Petr
a6fc2c09c6 PY-53693 PyCharm adds _: KW_ONLY to dataclass' init signature
GitOrigin-RevId: 471e10b4e12a36a640da2f3006719372797b5cf1
2024-07-08 17:53:13 +00:00
Mikhail Golubev
eb63148798 PY-73246 Don't insert square brackets after classes not having free type parameters
Even if they transitively extend typing.Generic, such as the builtin str.

GitOrigin-RevId: 9389ef5846e21ba5e0fed8b835beb2d458e42f13
2024-07-02 14:08:48 +00:00
Mikhail Golubev
ebba681c85 PY-62208 Don't suggest names shorter than five characters unless it's an extended completion
Otherwise, we end up with dozens of unintentionally public names such as "s", "i", "k"
even in the standard library (e.g. `this.s` or `pickletools.i`).

Ideally, we should rely on .pyi stubs and the content of `__all__` to offer only explicitly
exposed API, but not every module has any of those two, and it's not clear how to match
.py files and the corresponding .pyi stubs fast enough for completion.

GitOrigin-RevId: 163c472654e60ae63ff893142b8ddb9accc56393
2024-07-02 14:08:48 +00:00
Mikhail Golubev
1a3e6c2a64 PY-73246 Automatically insert square brackets on completion of parameterized types
GitOrigin-RevId: 5e81bc984fa3c7b4f83c564c85d872c5a49cf391
2024-07-02 14:08:48 +00:00
Mikhail Golubev
52850e21d8 PY-62208 Include importable names in basic completion results
Previously, such names were visible only on so-called "extended" completion,
activated when the hotkey for the basic completion was hit twice. The main reason
was that collecting such variants from indexes was a slow process, and we
didn't want to harm the responsiveness of completion for basic names.
Now it becomes possible thanks to a number of performance optimizations:

* Instead of using three separate indexes for classes, functions and variables,
we use one -- PyExportedModuleAttributeIndex. By definition, it includes only top-level
"importable" names, so we additionally save time by not filtering out irrelevant
entries. Also, it doesn't contain private definitions starting with an underscore.
It might bother some users, but given that the previous completion was used
extremely rarely, and the new one is going to be visible everywhere, it seems
that pruning unlikely entries as much as possible is a fare tradeoff. In the future,
we might enable them back on the "extended" completion if there is a demand.
Also, this index binds its keys to the project (`traceKeyHashToVirtualFileMapping`),
further eliminating useless index lookups.

* Thanks to the recent fixes in the platform (IJPL-265), it's now possible to
simultaneously iterate over all keys in an index and request values for a given key
without deadlocks, which is much faster than eagerly fetching all keys first.

* While scanning through all matching entries from indexes, we terminate
the lookup if the number of items exceeds the size of the lookup list.
We can further reduce this number by adjusting the "ide.completion.variant.limit"
registry value.

* Calculating expensive "canonical" import paths (e.g. "pkg.private.Name" is importable as
"pkg.Name") is offloaded to a background thread thanks to the `withExpensiveRenderer` API.
We still calculate these paths synchronously, though, for names whose raw qualified names
contain components starting with an underscore to decide whether these private names are
publicly re-exported and, hence, should be displayed.

The rest of the work has been put into reducing the number of entries on the list, e.g.

* The prefix under caret is now matched from the beginning of a name, e.g. `Bar<caret>`
matches `BarBaz`, but not `FooBar`.
* We don't suggest imported names clashing with those already available in scope.
* Some kinds of definitions are not suggested in specific contexts, e.g.
functions and variables are not suggested inside patterns and type hints.
* Nothing is suggested at the top-level of a class body, where dangling
reference expressions or calls are not normally expected.

Additionally, we don't suggest names from .pyi stubs at the moment, because
it pollutes the suggestion list with entries coming from the stubs for
third-party packages in Typeshed. We should probably enable them back once
we are able to properly disable Typeshed entries for not installed packages.

Some legacy forms of completion are left in the extended mode. In particular,
qualified names of classes are offered inside string literals only in this mode.
Also, module and package names are suggested only in the extended mode, because
top-level packages and modules are already suggested for the basic completion
by PyModuleNameCompletionContributor.

A few tests in PyClassNameCompletionTest were updated or removed entirely because
* we no longer suggest private names
* we no longer suggest names from private modules not re-exported in a public module
* we no longer suggest names clashing with those already available in scope
* prefix matching policy was changed to start at the beginning of an identifier

The whole feature can be disabled with the option "Suggest importable classes,
functions and variables in basic completion" in settings.

GitOrigin-RevId: 0787d42ce337b73b01a60f0bb7aa434fee43e659
2024-07-02 14:08:48 +00:00
Daniil Kalinin
d47bd34358 PY-58497 Refactor parameter info logic for Python
Show type hints only for the highlighted parameter

GitOrigin-RevId: f55d8ecc27dcbca5e6c24c5ca347ea3995e69ca8
2024-07-02 09:57:32 +00:00
Andrey Lisin
11c4b3a9be PY-60597 Clean up test data script
GitOrigin-RevId: 5ba5b6f38ea316c3c9bffeb82b4576e31d1e3c78
2024-06-21 13:48:29 +00:00
Andrey Lisin
7de4a58087 PY-60597 Move test data for PyCharm Professional debugger feature tests to professional test data path
GitOrigin-RevId: 04d6c9229c93cd7fd81474c48fc42df1d71bc83b
2024-06-20 18:27:43 +00:00
Andrey Vokin
170506beaa PY-73102 Presence of @warnings.deprecated or @typing_extensions.deprecated decorator suppressed errors about incorrect call arguments
GitOrigin-RevId: d1a5a4ce224fe92af9f0df376b63b8cb38ca3990
2024-06-17 22:26:51 +00:00
Andrey Vokin
f2a322c6d9 PY-73107 Usages of @warnings.deprecated inside .pyi stubs are ignored
GitOrigin-RevId: 7682eff8c8ca8ae8241ddee3191add34ab2ac22e
2024-06-17 22:26:51 +00:00
Petr
ee91d6a211 PY-72661 Literal completion inside nested parenthesis
GitOrigin-RevId: 14f18efcbaa520ac36ddd4892b774ed60a01cfdc
2024-06-17 20:36:23 +00:00
Andrey Vokin
673383c3da PY-61651 Deprecation highlighting with PEP 702 @deprecated decorator
GitOrigin-RevId: 426e7001d20849d7029fea55431d3e2cfae3eb11
2024-06-10 15:58:53 +00:00
Mikhail Golubev
8322bb476d PY-55086 Do not report raising a BaseException instance directly
See https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement.
I decided not to update the inspection description, because BaseException is not
intended to be inherited by user classes.
The check for Exception was removed because Exception itself extends BaseException.

GitOrigin-RevId: 5782c9351aebb524c4d0fc0c9f3307d8db682efb
2024-05-28 01:10:12 +00:00
Mikhail Golubev
93ac5fe566 PY-70528 Add support for typing_extensions.TypeVarTuple and Unpack
I've add-hoc updated typing_extensions.pyi in the bundled Typeshed to
recognize Unpack there.

GitOrigin-RevId: 953402e42984712a630c1772cf2f2cd4cbacdccf
2024-05-28 01:10:05 +00:00
Petr
c8509ccc80 [python] Support TypeVarTuple from typing_extensions
GitOrigin-RevId: 02ed108a55d3feed54d95bfb5552f31cdf3e4880
2024-05-24 22:15:34 +00:00
Egor.Eliseev
cb37afc53e PY-72060-DjangoTemplateDebuggerTest failed
Fix Log/Condition breakpoints for debugger plugins.
Fix Step Into, Step Over commands for debugger plugins


Co-authored-by: Andrey Lisin <andrey.lisin@jetbrains.com>

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

GitOrigin-RevId: b495a41fe37f61e4271d3438bab37846e0013006
2024-05-23 18:34:19 +00:00
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