Commit Graph

64 Commits

Author SHA1 Message Date
Irina Fediaeva
92365f2246 PY-52574: Update tests after removing Epytext docstring format
(cherry picked from commit d4a90a8da56ca889cf380aa5bc72ac82b0716abc)

IJ-CR-148150

GitOrigin-RevId: 235a0e447d84c96e9963235615b07a1caf371e74
2024-11-28 01:35:54 +00:00
Mikhail Golubev
535af53f05 PY-77168 Allow flow-sensitive resolve from unmatched version checks to reachable outer blocks
Also, don't query LanguageLevel for each element of each instruction,
only once per scope traversal.

This doesn't fix the problem with unreachable definition *inside* blocks under
unmatched version checks, i.e.

if sys.version_info < (3, 8):
    Alias = int
    expr: Alias # unresolved

but it's a more difficult problem how to handle those consistently with the idea
of unreachable version checks under the *current* interpreter version, and hopefully
it occurs rarer than, say, unresolved top-level imports of common names from typing.

(cherry picked from commit 55fd4597c6d0860d290caba15fbf4d313e985a86)

IJ-CR-149696

GitOrigin-RevId: 357ada7e10618aef75c470e6cd878f7672109e83
2024-11-25 22:38:29 +00:00
Mikhail Golubev
3d7e118c36 PY-77060 Remove spaces after * and ** in new-style PEP 695 type parameters
(cherry picked from commit cd38f49d0f28894e4f33dbd2fa331eaf895fd70d)

IJ-CR-148110

GitOrigin-RevId: 99164b1b95b89d7c4b729308c02a8d2800c2f20c
2024-11-19 17:59:42 +00:00
Petr
db52d4ec3d PY-34617 Take into account sys.version_info checks when analyzing Python files
Support version checks for import statements.

GitOrigin-RevId: df52f60574962e1bc222121aadc082683de0a869
2024-09-05 11:17:15 +00:00
Petr
79dc479c63 PY-34617 Take into account sys.version_info checks when analyzing Python files
Support and, or, <=, > operators in version checks.

GitOrigin-RevId: 5006e88b0f7935d0bf0841dfd5fad5c371e8ff12
2024-09-05 11:17:15 +00:00
Petr
93b9066edf PY-34617 Support version check
GitOrigin-RevId: 3318ff79cdcc5ba0ce5e4feb65abad5ad0f4acfa
2024-07-28 00:24:15 +00:00
Petr
5147d37e25 PY-34617 Code deduplication (PythonCommonCompletionTest)
GitOrigin-RevId: 20d48eb4e6d5620c182d388398dd80234b2eefe7
2024-07-28 00:24:15 +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
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
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
68c421f3d9 PY-42738 Incomplete handling of single and double quotes for dictionary keys in auto completion
GitOrigin-RevId: ed480e40c4de292d38efbe59656cf3c8eb234435
2024-04-25 23:00:28 +00:00
Petr
2409f9f494 [python] Reduce code duplication in PythonCommonCompletionTest
GitOrigin-RevId: 1e39bed5d00d3253907dc0d8cedbd37d323a9859
2024-04-25 23:00:28 +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
Daniil Kalinin
b83be81bb7 PY-61878 Resolve type parameters and type aliases on stubs
Do not resolve type parameters as class members

Tests for the changes above

Co-authored-by: Mikhail Golubev <mikhail.golubev@jetbrains.com>

GitOrigin-RevId: 96309ebedf26d04e375bfa3a5f8ae0bc9257d48f
2023-11-06 19:59:18 +00:00
Mikhail Golubev
98016a1ae6 PY-63367 PY-63366 Include instructions for annotations of new-styles generic functions in their own CFG
This way they have access to type parameters of these functions, and PyReferenceImpl.getResultsFromProcessor
can properly perform flow-sensitive resolve for them now that READ instructions for expressions
inside annotations and WRITE instructions for type parameters are in the same CFG. It allowed to
remove all the special logic for type parameters from PyReferenceImpl as well as from
PyUnboundLocalVariableInspection.

I had to special-case these annotations in PyResolveUtil.scopeCrawlUp, though, to "lift" their
original scope back from what ScopeUtil.getScopeOwner returns, making names defined in a class scope,
e.g., nested classes, visible to them.

GitOrigin-RevId: b2e78211565300dbcd7c2e2b246a7a8e14bb0e8f
2023-10-16 23:42:44 +00:00
Mikhail Golubev
8a5536359d [python] Simplify PyCommonResolveTestCase.assertNotResolved
GitOrigin-RevId: 26bd034de5e26ec2438f9e98a4ce648f96f04707
2023-10-05 22:02:21 +00:00
Daniil Kalinin
97185d17c8 PY-62608 PEP 695 Type Parameter Syntax: Resolve and scoping for type parameters in type aliases
GitOrigin-RevId: be532456e7a9c470d5d0a2770a7a2eb9b9b6e8de
2023-09-28 15:05:33 +00:00
Daniil Kalinin
3a70f1d22d PY-61854 PEP 695 Type Parameter Syntax: Formatting
GitOrigin-RevId: 272f956033d82626d7cf689aa561cdeab3f951da
2023-09-15 16:04:46 +00:00
Olga.Lavrichenko
c9b1045a46 DS-5427 DS-5549 Fixed parsing magic commands after empty cells
GitOrigin-RevId: d2359bacd7f772ebeaaabe7d1d43da060d2f7928
2023-09-12 13:48:51 +00:00
Mikhail Golubev
63d24cbb9d PY-34493 Enable back copying annotations from third-party .py files on Override/Implement
Since disabling turned out to be controversial. Even in the ticket some users were
against this decision claiming that it heavily annotated code bases it might be necessary
to retain all annotations from inherited method signatures. We need to think of a better
solution for controlling this behavior on case-to-case basis.

GitOrigin-RevId: c68763f0cad23de8975085e9bc8a6fd99013de3b
2023-08-09 20:53:35 +00:00
Mikhail Golubev
a2af264b63 PY-45588 Add necessary imports on completing methods of superclasses to override
I had to move addImports to PyClassRefactoringUtil because PySuperMethodCompletionContributor
resides in python-psi-impl and, thus, has no access to PyOverrideImplementUtil.

GitOrigin-RevId: cf2ac19da779977649144b2477bac3f8ae78bbcd
2023-08-09 20:53:35 +00:00
Mikhail Golubev
b50c617b7c PY-34493 Don't copy annotations from .pyi stubs and libraries on super method completion
GitOrigin-RevId: 65787827f5df5aa80986107dda0ba555b0942d40
2023-08-09 20:53:35 +00:00
Olga.Lavrichenko
d4df46d5f0 DS-4478 Reformat code removes spaces in shell commands
GitOrigin-RevId: b06215e01de70329f3c9dfef4ea330ea73400cd2
2023-07-24 17:24:56 +00:00
Daniil Kalinin
2983980cbd PY-17193, PY-10709 enable Use parentheses instead of backslashes for breaking lines option by default
Change tests according to the new default value

GitOrigin-RevId: 79a09911127532fadcc4a4d37a454887d46effa9
2023-07-07 13:26:55 +00:00
Olga.Lavrichenko
6df5bfd10d DS-1584 DS-2583 Reformat breaks IPython magic commands and shell commands
GitOrigin-RevId: 949528c951d6c9174b1bad21452a90fbdb07b418
2023-01-16 15:13:23 +00:00
lada.gagina
01f87f5c77 PY-42637 Fix quotes for TypedDict keys completion in subscription expressions
If there are quotes, suggest just the key names

GitOrigin-RevId: 58caea6ba1ceeeea790580c3d24d255a636764bb
2023-01-10 17:39:28 +00:00
Daniil Ovchinnikov
578eaaf60e rename library kotlin-stdlib-jdk8 -> kotlin-stdlib
GitOrigin-RevId: cddf45ccfd5563d3fe209bea62a1c37c94f44ff9
2023-01-10 12:22:34 +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
Irina.Fediaeva
181edc5caa PY-50788: Correct resolve for inherited docstring attribute names
Now during resolve if there is no class/instance attribute with appropriate name explicitly in the class, we will try to find it in the parent classes and resolve there.

GitOrigin-RevId: 52ab5f0ad63cba187457ba3db6107997ede33dee
2022-10-03 13:21:34 +00:00
Tagir Valeev
adb060863f Text blocks used
GitOrigin-RevId: 7db538c0a10131a3f946436c85b42fe7d7dc5b10
2022-09-29 12:58:29 +00:00
Irina.Fediaeva
cce0ef17d5 PY-16760, PY-28549, PY-35743, PY-55609, PY-46654: Correct resolve of class attributes in docstrings
Previously in docstrings we incorrectly recognized references in 'Attributes' section only as instance attribute references. It led to false positive 'Unresolved reference' on class attributes references in docstrings and wrong resolve when using class and instance attributes with the same names. Now we use ReferenceType.VARIABLE to identify both class and instance attribute references in 'Attributes' section and then resolve them with priority of instance attributes. Also fixed wrong resolve of attributes references to constructor parameters.

GitOrigin-RevId: ea10bfb092472c0ab14b77f06efd93093cfcd684
2022-08-25 21:11:57 +00:00
Alexey Kudravtsev
85895e8989 add more SSR: replace stream expression with ContainerUtil call
GitOrigin-RevId: 629f61b8d4541fb374dedcbbce2964ddb70dfdf1
2022-08-24 11:15:49 +00:00
Daniil Kalinin
fb11ee327c PY-53200 do not autocomplete parameter list if method already have one
Test for PY-53200

Better tests for PY-53200

PY-53200 Removed unnecessary test.

`testMethodNamesDoNotDuplicateParameterList` renamed and moved closer to the corresponding ones
Removed test for method names in suggestions restored

GitOrigin-RevId: 51b0721190718c44810c16e198bad583c2af67d0
2022-05-05 11:18:29 +00:00
Semyon Proshev
7b8b5bb12f Make creating resolve context with explicit type eval context shorter
GitOrigin-RevId: 7dce0f1869ca114d729f8368273291940eda21ef
2021-06-13 14:50:11 +00:00
Dmitry Jemerov
749ce8a332 Cleanup: remove @author tags
GitOrigin-RevId: 9174eb8d77215b16f9f6c6074e6aced654d95ef1
2021-05-03 13:07:48 +00:00
Lada Gagina
726f21a3ae PY-44026 Add a flag to PyModuleNameCompletionContributor for some tests to pass
GitOrigin-RevId: 104959faf4784de40500b694556b552fdbb69021
2021-02-17 15:56:37 +00:00
Vladimir Krivosheev
99cc95ff68 cleanup
GitOrigin-RevId: a6e02daa32397b805eb1a1aa9c9855f092548eb6
2021-01-22 20:58:21 +00:00
Irina Fediaeva
48e8e52668 PY-36062: Add resolve attributes matching PyModuleType.MODULE_MEMBERS to types.ModuleType attributes. Add matching PyClassType: ModuleType to PyModuleType.
GitOrigin-RevId: d2988397e4a58f9170a90cd6a3251054dedf896f
2020-12-16 13:31:50 +00:00
Semyon Proshev
fbbb78bc4e Change receiver for initialization calls and don't resolve callee to constructors
Callee is now a receiver for these cases, previously it was `null`.
Callee is not replaced with constructors to have an ability to map it onto self/cls parameters and process `(cls: Type[T], ...) -> T` annotations.
Stay with the previous behaviour for navigation and looking for target element.

GitOrigin-RevId: c0f9894cf50fd5d7fd325f095976d096fb948e89
2020-11-11 19:30:34 +00:00
Mikhail Golubev
2d4cada4b3 PY-25832 Consider only class attributes for TypeVars wrapped in typing.Type
GitOrigin-RevId: 7cbdabfcbb5acad68e801c0c755a84acae7e8310
2020-09-18 11:47:26 +00:00
Mikhail Golubev
69aae259b1 PY-25832 Consider upper bound and constraints for completion and resolve on TypeVar
GitOrigin-RevId: c6b428965b0136f7f6051c992038dc15819b8f14
2020-09-18 11:47:26 +00:00
Vladimir Krivosheev
d4e9b09e26 cleanup (final)
GitOrigin-RevId: 93607e195763f2acf29ee0d7a280d7e07e8d2f14
2020-06-26 12:21:17 +03:00
andrey.matveev
edbd512159 PY-42772 Impl filtering positional only arguments
GitOrigin-RevId: 978dd1f4970d5b1aaa94e251cbf81dee51f2f36c
2020-06-08 10:11:19 +00:00
andrey.matveev
c4bf5bc2fc PY-42520 Impl filter repeated named args
GitOrigin-RevId: f68f51219b49792f109f94352e83f5671d53f3dd
2020-06-03 15:51:55 +03:00
andrey.matveev
3055c4293a PY-41676 Fix hasattr resolve issue str object is not callable
GitOrigin-RevId: aa9583ab678dd48a9264209b9bb2545b435e9d26
2020-05-22 11:46:28 +03:00
Vladimir Krivosheev
f2a72b34fa do not export trove from util module
GitOrigin-RevId: 666bf5e1fc45045bb9b1c391b7ec5a2ac4b65dde
2020-05-16 16:34:43 +00:00
Semyon Proshev
40c9d375e5 Don't consider metaclass.__call__(cls, *args, **kwargs) as a possible constructor (PY-17877, PY-41380)
GitOrigin-RevId: de83bde719d08de70dcff7f3ad7dfa722a66af72
2020-04-28 21:08:25 +00:00
Ilya.Kazakevich
18c1e98d54 Logging deprecated method usage
GitOrigin-RevId: f477b9aa83e5337399a5b798a21cd0d5c1490d7c
2020-04-26 22:37:36 +00:00
Lada Gagina
61ad4c3109 IDEA-CR-61508: PY-39703 Add TypedDict keys completion
GitOrigin-RevId: b4e71d5edff69b23e1f1eb68ffe77f994a6a0293
2020-04-16 20:10:49 +00:00
Aleksei Kniazev
c7d2f911af IDEA-CR-60308: typing-related items for stub files are not reexported for completion (PY-38172)
GitOrigin-RevId: d929f1cba63ece706ab415f7a7d2bd80accff40f
2020-03-23 14:01:42 +00:00