Commit Graph

96 Commits

Author SHA1 Message Date
Mikhail Golubev
97b22aaa13 PY-42200 Support parenthesized context managers in Python 3.9+
In case of syntactic ambiguity with previous versions of the grammar, such as
"with (expr)" or "with (expr1, expr2)", PyWithStatement is still parsed as
having its own parentheses, not a parenthesized expression or a tuple as
a single context expression. The latter case, even though syntactically legal,
is still reported by the compatibility inspection in Python <3.9.

These changes also include proper formatter and editing support (e.g. not
inserting backslashes on line breaks inside parentheses), as well as
Complete Current Statement, which now takes possible parentheses into account
while inserting a missing colon.

The changes in the formatter are somewhat ad-hoc, intended to minimize the effect
on other constructs. "With" statement is somewhat special in the sense that it's
the first compound statement (having a statement list) with its own list-like
part in parentheses.

Existing tests on with statement processing were expanded and uniformly named.

Co-authored-by: Semyon Proshev <semyon.proshev@jetbrains.com>

GitOrigin-RevId: 15c33e97f177e81b5ed23891063555df016feb05
2022-05-04 12:31:37 +00:00
Dmitry Trofimov
aacc1d4ac5 Fix messages according to https://jetbrains.team/p/ijpf/reviews/4476/timeline
GitOrigin-RevId: cd390d2c7cf61f43a554d198f98f7375d872ffa5
2022-02-22 11:29:30 +00:00
Dmitry Trofimov
8d6f3c7566 Fix messages according to https://jetbrains.team/p/ijpf/reviews/4343
GitOrigin-RevId: cc2a22c7ff04abc7e5d9b763e1f67ba144d47462
2022-02-22 11:29:28 +00:00
Mikhail Golubev
3b6dea06a3 PY-21398 Wrap batch updates of existing usages in quickfixes with PotemkinProgress
It also fixes EA-425763 about using incorrect parent and anchor elements
to insert a function generated from a method of a nested class.

GitOrigin-RevId: f9b9da303396eb78c2c12b2750065dbdc0ba70ed
2022-02-17 09:28:34 +00:00
Lada Gagina
72772c55da PY-46661 PY-43387 TypedDict type-checking in call expressions: report value type errors, missing and extra keys
GitOrigin-RevId: ad8c2e37cf893e50aeda7a54d113dec571b0d135
2022-02-10 23:02:25 +00:00
Lada Gagina
bc28fa5645 PY-46661 PY-43387 TypedDict type-checking in target expressions: report value type errors, missing and extra keys
GitOrigin-RevId: 9636c8e032f9d084d7a5c3a8036e54422b8dd222
2022-02-10 23:02:21 +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
Dmitry Trofimov
6cfea6e0b5 CodeServer: Python extract method refactoring, also decouple platform Rename refactoring from UI and lang modules
GitOrigin-RevId: fbe188a96f7eeaa168d6acf2874b1b759b9d8791
2022-02-01 19:19:46 +00:00
Dmitry Trofimov
a9a116522a CodeServer: Python introduce variable refactoring
GitOrigin-RevId: 9404442216786c92508c4a8f4bece96013683083
2022-01-24 19:34:17 +00:00
andrey.matveev
3ae3780538 PY-26881 Fix getLocationString messages
GitOrigin-RevId: 42a5a38b321e8611b9eb466a8cec675cb430cbd1
2022-01-24 05:57:47 +00:00
andrey.matveev
0210695327 PY-26881 Use stubs for function in find usages if it exists
(cherry picked from commit 060c164c3f01a857561d5d0341a186464419e845)

IJ-MR-17639

GitOrigin-RevId: 88141ea74ff22fb022056c8d6d7f70222a3f9b74
2022-01-21 03:17:30 +00:00
andrey.matveev
30d0fd71ad [PyCharm] Fix UnusedPropertyInspectionTest delete unnecessary QFIX.define.attribute.in.init
https://buildserver.labs.intellij.net/investigations.html#testNameId5820486536545895157

GitOrigin-RevId: e0c96746015539a61c7ff0f44712c34a9fdbd351
2021-10-21 07:46:18 +00:00
Mikhail Golubev
e9d11d1215 PY-48010 Warn about problems causing SyntaxErrors in PEP 634 patterns
GitOrigin-RevId: 718645cc5dfd6d0a14f1bd802f3c5bb2bb2c6074
2021-10-18 13:57:02 +00:00
Mikhail Golubev
0686325b90 PY-49774 Warn about PEP 634 match statements in Python < 3.10
GitOrigin-RevId: 092f708faf2f35454a8214e56c2dfd6ab43b3e27
2021-10-18 13:56:58 +00:00
andrey.matveev
1156723b14 PY-33055 Fix move attribute to __init__ method quickfix
(cherry picked from commit cd6abb8ad8a01b22066bed85639242b03a85d1d0)

IJ-MR-8050

GitOrigin-RevId: f8a350835ce303c96b7f404263d8367242f4eaa6
2021-10-12 06:16:05 +00:00
andrey.matveev
1fe7e5443c PY-49283 Add quick fix for from future import annotations
(cherry picked from commit 7d26e211c67f2574078e1f0e8951f744889d82d6)

IJ-CR-10316

GitOrigin-RevId: 34d4bc72b11613c0603587c1c0a9e640b0add023
2021-08-30 20:48:41 +00:00
andrey.matveev
dc92b76960 PY-49935 Fix internationalization for type hints illegal first parameter
GitOrigin-RevId: b935d911596026f591bfb06a2c95ba6d07ab2293
2021-08-25 05:50:50 +00:00
andrey.matveev
997b58df49 PY-49935 Impl type inference and type checking for PEP 612
Support type hints and type checking for typing.ParamSpec and typing.Concatenate

(cherry picked from commit 7854b3386ccdffc0091664e0923622cd8c093fc9)

IJ-MR-12970

GitOrigin-RevId: 4578cb463b6ab8fc244766bfaccb122d0e2b7479
2021-08-23 17:52:45 +00:00
Mikhail Golubev
3abdca30b5 i18n: Extract intention groups "Python" and "Django"
GitOrigin-RevId: e70b02e7c5f051ba254a13a06917083f29f5bfb3
2021-07-07 11:44:14 +00:00
Mikhail Golubev
a398ea0e21 Remove unreachable code and messages related to indented blocks from the parser
PythonIndentingProcessor ensures that INDENT tokens are never inserted at EOF
and before indented comments. Also, parsing of indented blocks is written so
that DEDENT tokens always appear at their end, unless it's EOF, so no need to
report its absence.

GitOrigin-RevId: f4a8270ead3b3d3cae751727e8379c66659913ed
2021-06-24 16:26:20 +00:00
Semyon Proshev
3abad011a1 Improve wording for ipython introspection syntax error
GitOrigin-RevId: 7f4566b2da24cb4cc0d9eed025027e44b03d53cd
2021-06-23 14:04:00 +00:00
andrey.matveev
ebe8f93812 PY-44974 PEP 604: Support Python3.10 unions
Support | syntax for python unions.
Also support type | None as a new style for Optional.
Fix highlighting unresolved reference issues with | syntax.
Type inference from isinstance and issubclass.
Add quick fix to switch to old-style syntax in earlier python versions (<3.10)
Fix quick documentation to render new syntax.

(cherry picked from commit 6a64ee12c2d8503a0ef102e8b67cb0b95ce77999)

IJ-MR-8400

GitOrigin-RevId: c26b868fc61f26936a3316ec06f78b66d75f6857
2021-06-14 14:38:25 +00:00
Alex Plate
79820165d3 [IDEA-270680] Use an ellipsis character in the py bundle
GitOrigin-RevId: adea0d6db24bc18295954f1a48a9a04db8cf8d0b
2021-06-03 17:21:10 +00:00
Mikhail Golubev
639b8d1029 PY-48008 Implement parsing of PEP-634 match statements
All the corresponding PSI elements now have empty interfaces. The API will be
"beefed up" as we start adding actual processing of them in the code insight
(e.g. for the upcoming CFG and inspections).

The trickiest part of the parsing was the recovery. Patterns allow only
a limited subset of expression syntax, but I tried to sensibly consume and report
everything else (not building PSI for it). So that if user starts typing more
general expressions in the midst of a pattern, we still give meaningful error
messages. It seems a likely cause of errors when the feature first rolls out in
Python 3.10.

GitOrigin-RevId: fae40034964e4a25d91dab06a43d3fc07225d9c7
2021-05-24 10:28:29 +00:00
Semyon Proshev
cb8716794e Update python intentions' descriptions (PY-48274)
GitOrigin-RevId: 2bd596ec3f37c94303661b2aa416970aafc03ab6
2021-04-30 11:55:25 +00:00
Semyon Proshev
cf78619d36 Update python inspections' descriptions (PY-48274)
GitOrigin-RevId: 4ee6b7ef7e51a697e4d52a06b87cf599c79366a0
2021-04-30 10:35:14 +00:00
Semyon Proshev
1f898d43af Remove PyStringExceptionInspection and PyWrapInExceptionQuickFix as no longer relevant for supported python versions
GitOrigin-RevId: 9718219e670d2fe0a8e7c710f9c789c9b8f25dd9
2021-04-30 10:35:10 +00:00
Dmitry Trofimov
233555883b Extract Python annotators
GitOrigin-RevId: fb1e36f2815fc9ef59ad2d7b6bb84ff372527423
2021-04-28 15:07:41 +00:00
Andrey Vlasovskikh
6d8428ee4e PY-46321 Renamed PyDocstring into Doctest to make more sense as a user-visible name in Markdown code fence blocks
GitOrigin-RevId: 1284ab756e522db0c8109b59d6d78b1d1f503a7f
2021-04-27 17:32:03 +00:00
Louis Vignier
0f575fbfa5 IJ-CR-8338 [codeInspection] Update ListEditForm
GitOrigin-RevId: 60b16d88ad47f62ad56aea840e2c6b381f54f5ea
2021-04-19 19:09:02 +03:00
Alexey Kudravtsev
ecad62483f provide readable file type name (instead of e.g. PLAINTXT), unify property names for file type description, add test for having getDisplayName() in a FileType
GitOrigin-RevId: eb857f57def6d82a2051fc2610a24de266ee8386
2021-03-09 12:18:29 +00:00
Semyon Proshev
9705a90e2f Don't show a modal dialog with untrusted venv warning, consider click on quick-fix as a permission (PY-41524)
GitOrigin-RevId: 19c05fb733c2a2070219d74290231e83e3b38071
2021-03-03 16:21:12 +00:00
Semyon Proshev
4c3ba38f00 Tune untrusted interpreter warning (PY-41524)
GitOrigin-RevId: d8952d4cbc6658fa6ae4182d89b10dc856f3290a
2021-03-02 10:03:17 +00:00
Semyon Proshev
5798ffd476 Ask for confirmation before configuring inner venv as a project interpreter (PY-41524)
GitOrigin-RevId: d87ccc1432821a34c7b46036e834c41d7ad02a87
2021-02-25 13:34:17 +00:00
andrey.matveev
88edc899f1 EA-249996 Use different names for remove unused locals quick fixes
(cherry picked from commit 6ee1dae626fb79c827e538a3edb6a9ca12a0965d)

IJ-MR-5038

GitOrigin-RevId: fdfed5324edd72125c9a6550a7034c73cab40d83
2021-01-21 04:41:03 +00:00
Petr Golubev
210fd9eb45 LAB-31: extracted optimize imports quick fix
GitOrigin-RevId: 0011495a43d4afe392c907fad710390a66953bef
2020-12-03 20:18:26 +00:00
alla redko
21fd617dde IDEA-248847
GitOrigin-RevId: bb376e267543e459a630b5802399cd6c0467ddff
2020-11-30 22:16:31 +00:00
Petr Golubev
1e0a48cb6c mv PySignatureCacheManagerImpl to intellij.python.psi.impl
GitOrigin-RevId: eb8f8dbe0db9396ba9339d605ce726e99062dc15
2020-11-17 16:45:17 +00:00
Irina Fediaeva
1e8a086708 PY-35698, PY-33565: Delete obsolete PyCallByClassInspection. Type checker inspection covers most of the cases since there is always some type inferred for cls/self.
IDEA-CR-68591

GitOrigin-RevId: fef66f2e1e4d17de50fcca248a3ddc957f3c316d
2020-11-10 13:31:16 +00:00
andrey.matveev
c5ae9550ce PY-42750 Allow same directory imports in Python 3 and introduce explicit namespace packages
There are 3 types of directories: plain directories, ordinary packages (with
__init__.py) and PEP 420 namespace packages. There are 3 types of imports:
absolute (from a root), same directory (absolute import from the current
directory when it's not explicitly marked as a root) and relative imports
(imports that start with dot).

Absolute imports are correct in all kinds of directories.
Same directory imports are correct in Python 2 in all cases and in Python 3 if
we have the directory containing the script with this import in Python path at
runtime. Users of Python 3 often face the problem when they can run the script
from the console because the directory containing this script got into Python
path but still have red underline and an unresolved reference error in the same
directory import because PyCharm didn't know that this file will be used as a
program's entry point. Previously, the way to fix such a problem was marking it
as a source root. But this action was not so obvious, especially for newcomers.
With this feature, such imports resolve successfully and now it is not necessary
to mark directories as source roots.

Relative imports are correct only in Python 3 namespace or ordinary packages and
should not be used in plain directories. If we have a relative import in plain
directory we highlight it with a weak warning and suggest 2 ways of fixing that:
marking directory as a namespace package explicitly (with quick fix or with Mark
As | Namespace Package) or changing this import to the same directory import
with a quickfix or manually.

Explicitly marking namespace packages can later be used for automatically
running files from them and ordinary packages with "-m".
The new resolve policy and explicit namespace packages can be disabled with the
Registry flag "python.explicit.namespace.packages".

These changes also address PY-40396. Namely, now any directory with __init__.py
inside or explicitly marked as a namespace package has a package icon,
regardless of its name or parents.

GitOrigin-RevId: 310fa562eb60121243cb6d68386ffc3e45c73245
2020-10-21 16:04:26 +00:00
Mikhail Golubev
bb31fdc67d PY-42334 Add support for PEP 613 typing.TypeAlias
Both typing.TypeAlias (available only in 3.10) and typing_extensions.TypeAlias
names are supported.

RHS values of assignments annotated with TypeAlias are always retained in
stubs and injected into (if it's a string literal), regardless of whether
they look similar to a well-formed type hint. It seems natural to assume
that if a user employs such as specific marker as "TypeAlias" at all, they
clearly indicate that the value is supposed to be a type.

The inspections "Type hints definitions and usages" and "Final classes, methods
and variables" properly analyse RHS of assignments annotated with TypeAlias.
Type hinting inspection also reports illegal usages of TypeAlias, as it was
done for other special forms in the typing module.

The type of such variables themselves is Any, however they're still displayed
as having the type "TypeAlias" in Quick Documentation to avoid confusion.

GitOrigin-RevId: fab02f6e1060c0994e1d21201768e7b28ba7d9e0
2020-10-19 19:46:54 +00:00
Vasya Aksyonov
226cf2c350 PY-15046: Invert 'if' statement implementation
GitOrigin-RevId: 86ddfbe04b635d9db288b273540d06d83963cebe
2020-10-19 15:47:25 +00:00
Semyon Proshev
d30fc4f7bc Inline language level flags that are constants in supported python versions
GitOrigin-RevId: 5e381b72505c1d896028da83b7044be51e408f0b
2020-10-16 12:24:31 +00:00
Mikhail Golubev
d4262ba517 i18n: Extract messages about unresolved docstring parameter and import references
GitOrigin-RevId: d2a782498ce3381da8442f25bf7e93b45fb1ecdb
2020-08-26 14:25:34 +00:00
Mikhail Golubev
d71e53b405 i18n: Extract messages from and annotate remaining Python intentions
* SpecifyTypeInPy3AnnotationsIntention
* ImportFromToImportIntention
* ImportToggleAliasIntention
* ImportToImportFromIntention
* PyGenerateDocstringIntention
* SpecifyTypeInDocstringIntention

Some of them were additionally simplified by replacing their custom
field for an intention's name with the inherited one.

GitOrigin-RevId: 72e4c1b5fe628eca36496d56396ee9e149f5104f
2020-08-25 08:47:09 +00:00
Mikhail Golubev
63be8f70f2 i18n: Extract messages from and annotate remaining Python annotators
* FStringAnnotator
* Pep8ExternalAnnotator
* AssignTargetAnnotator

GitOrigin-RevId: 73b2feabd42c7061b4dad22e5d7f7a31ad3f338d
2020-08-25 08:47:08 +00:00
Mikhail Golubev
e8612fce3a i18n: Rename .family and .text messages in PyPsiBundle
GitOrigin-RevId: deead25466bd99be53843ee7f1c1d8f3a62191b4
2020-08-25 08:47:07 +00:00
Mikhail Golubev
566dd6af21 i18n: Remove more unused messages from PyPsiBundle
Some inspection had duplicated messages for their names. Normalized those
to use "INSP.NAME" keys for that purpose and removed unused copies.

Also, one of the messages was used only in a test commented ten years ago.
Got rid of that and the corresponding test data.

GitOrigin-RevId: c859370a8b62079e9e345cd03386da850de28586
2020-08-25 08:47:06 +00:00
Mikhail Golubev
827aa32a90 i18n: Fix a typo
GitOrigin-RevId: 8d8af0601dfc7dc68a669ccbf14395ff758387c6
2020-08-25 08:47:05 +00:00
Mikhail Golubev
df56210439 i18n: Remove unused and rename messages in PyPsiBundle containing "$N" in keys
These are not properly supported and often falsely reported as unused.

GitOrigin-RevId: cb9c9ce8096e14ecaff0b4f473cbb4a028eb3b44
2020-08-24 13:16:59 +00:00