216 Commits
Author SHA1 Message Date
Daniil Kalinin bc182ae806 PY-79967 Add a couple of tests for template strings to PythonParsingTest
GitOrigin-RevId: b760b2c6a0aa93118971c005a7ebe680d0c5000c
2025-05-09 11:12:01 +00:00
Daniil Kalinin c07b124c92 PY-72185 Use PythonHighlightingLexer instead of plain Python lexer in reparse check of PyReparseableIdentifier
The problem previously appeared in situations when an identifier was changed to a keyword, i.e. `a: Tru` -> `a: True` and `True` keyword was not highlighted properly as it was substituted by an identifier AST leaf as is bypassing the highlighting lexer

Add a couple of tests on it

GitOrigin-RevId: ec25d2115ec650bf781a9fe8140e8708e849ff60
2024-11-08 11:30:12 +00:00
Daniil Kalinin 0e2764b76b PY-72185 Improve reparse checks for single and triple quoted reparseable strings
Add a couple of tests on it

GitOrigin-RevId: 3e889638a8b13059c2b14914e64aea91c1f86445
2024-11-08 11:30:12 +00:00
Daniil Kalinin b934cfe38a PY-74231 Fix false positive "Statement expected, found Py:DEDENT" for a nested type alias
GitOrigin-RevId: 03d64abe2c949a5912eb5c16ef48a5149568d66f
2024-10-01 11:43:14 +00:00
Mikhail Golubev 132461b7de PyDecoratorImpl.toString() doesn't cause unstubbing
GitOrigin-RevId: a87b3874af518dcaf81384b25b85b76f618bdd1d
2024-09-09 11:34:15 +00:00
Daniil Kalinin 7751fceaed PY-71002 PEP-696: Support new syntax for default types of Type Parameters in new-style declarations
- PEP-696 adds a new syntax for declaring the default types of Type Parameters in new-new style generic classes, functions and type alias statements. Support these grammar changes.
- Store info about default types in stubs for Type Parameters
- Increment the stub version counter in PyFileElementType

GitOrigin-RevId: b6b22e3eaa86ce06132885781e5775a89bf4b840
2024-09-07 11:11:12 +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 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
Daniil Kalinin 19a4b1d01c PY-64326 tests for incremental parsing of PyStatementList
GitOrigin-RevId: 83e5343e9a164d92f8a5acf43b9ef0790e4a5ce3
2024-05-07 17:30:41 +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 10808546fc PY-63393 Handle keywords terminating lexing of f-strings fragments in the lowermost JFlex lexer
Previously, we acknowledged them in PythonIndentingProcessor.adjustBraceLevel, inserting
synthetic STATEMENT_BREAK in front of them to stop recovery in the parser, similarly
to how we handle other kinds of incomplete brackets, but the state inside PyLexerFStringHelper
was not reset, so it kept trying to find matching closing brackets, quotes and interpreting
colons as PyTokenTypes.FSTRING_FRAGMENT_FORMAT_START instead of just PyTokenTypes.COLON.
The state in PyLexerFStringHelper and PythonIndentingProcessor became out of sync, which
led to assertion violations.

It's not an optimal solution, since now these tokens are listed both in
PythonTokenSetContributor.getUnbalancedBracesRecoveryTokens and in Python.flex lexer
specification, and we need to keep them in sync. Also, PythonTokenSetContributor
can provide additional tokens from other languages, such as Cython. But it's simple
and seems "good enough" to patch the problem in the release.

GitOrigin-RevId: 4e156314cc02aba0634d5d9e3008177f49105051
2023-10-05 22:02:27 +00:00
Mikhail Golubev b3351b941e PY-59594 PEP 701: Stop recovery of incomplete f-string fragments at statement-only keywords
(cherry picked from commit 7aa912a43d63f6c9867d772e120c5b45adb10be3)

IJ-MR-115763

GitOrigin-RevId: ca6909a8e7a59e06eae69b631160e4d48541ce58
2023-09-29 09:33:45 +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 8b217ed53a PY-61853 PEP 695 Type Parameter Syntax: Parsing
GitOrigin-RevId: 286b53bb4e69cf1deb58dc75f41652e6a12a3af3
2023-09-15 16:04:41 +00:00
andrey.matveev ecd113fc12 PY-52930 Support except star
(cherry picked from commit 4d03313cce07e4c3ff4748328cf2e04ba74b8d91)

IJ-MR-24242

GitOrigin-RevId: fa6c1b9077ef78b35c8f3453debcf06bcbc96364
2022-05-18 00:19:37 +00:00
Mikhail GolubevandSemyon Proshev 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
Irina Fediaeva 333e20478b PY-48940: Allow unparenthesized assignment expressions within sequence indexes, but not in slices.
(cherry picked from commit c8bfbc4149b840033f9c24a9190860abdd0ff6a8)

IJ-CR-11891

GitOrigin-RevId: 3ce6f98d5b031c705c461505a5c307c0241ce97e
2021-08-10 13:00:59 +00:00
Irina Fediaeva a86c492a92 PY-48940: Allow unparenthesized assignment expressions within set literals, set comprehensions.
(cherry picked from commit 1ed44bb7a0bde2c7000923c2ed2a671f913eae8f)

IJ-CR-11891

GitOrigin-RevId: bb0ae8626e085e6c9223626137dbdd07e5c084b3
2021-08-10 13:00:58 +00:00
Mikhail Golubev 0db66c81a5 PY-49990 Parse a match statement without a subject as a type declaration
GitOrigin-RevId: 5c6dc8257973dd0f22a5ef8dd5883628205689a7
2021-08-09 14:39:03 +00:00
Mikhail Golubev 20097f7a69 PY-49785 Properly recover from "case" keyword in the middle of a match statement
Not stopping at a statement break token and continuing recovery until a colon,
we considered the subsequent well-formed case clause to be a part of an error
message about a missing pattern, thus, moving the caret to its colon.

GitOrigin-RevId: f4ee0e12876960e989de3dee89925b65e3cf2339
2021-07-19 16:29:15 +00:00
Mikhail Golubev e1b52ae759 PY-48008 Improve test coverage of match statements parsing
GitOrigin-RevId: 347185106d7fec7117c31b10fa24b709a3b0da42
2021-06-24 16:26:19 +00:00
Mikhail Golubev 70efe3108f PY-48008 Report missing subject expression in match statements
GitOrigin-RevId: 2c49ea19ac0fb5bdda966e4077c45321c397df8a
2021-06-24 16:26:18 +00:00
Mikhail Golubev 98d196aec6 PY-48009 Add automatic indent inside match statements
Namely, for their case clauses and inner comments.

Right now, each of them is indented on its own, as a separate formatting block.
It's still not entirely clear whether we should have a dedicated indented
container element for case clauses, similar to PyStatementList for statements.
It might simplify the formatter and some editing actions, but cause confusion
between the two container elements.

GitOrigin-RevId: 69184d2f8f78e2e113e8f40a310bb13ac0b5e71a
2021-05-24 10:28:35 +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
Andrey Vlasovskikh dfbab3186a PY-47974 Fixed missing components for running PythonConsoleParsingTest
GitOrigin-RevId: 7391ba5f43c770ebbc1cbbcde8b72387c5c90ea7
2021-04-08 00:23:08 +00:00
Andrey Vlasovskikh 4bd67d428d PY-47974 Parse single string literal in Python console as string, not as docstring
We assumed that if the first token of a Python file is a string literal, then it's a docstring. It's not the case for the Python console, where each input is a separate "file".

Now we pass the `PythonLexerKind` to the `PythonLexer` so that we can parse string literals differently if we are in the console "file".

I've also added Cython as a lexical kind for the Python lexer, since there is at least one place in the lexical rules that is specific to Cython. Also we have separate lexer subclasses for Cython, so having it expressed as a kind for the JFlex rules seems logical, even if we don't use it right now.

GitOrigin-RevId: f5e34fa2dc3b3da84cacf6cee69a4ba0ee674ad5
2021-04-07 22:34:46 +00:00
Mikhail Golubev de08c2a947 Fix Python tests after the proofreading
GitOrigin-RevId: 2f6eb873d6321ef00d293377ec2c97195f72da21
2020-11-30 22:17:55 +00:00
Semyon Proshev 48a952a327 Make parser stricter for for statements and expressions (PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: 199f30b819c85a4eba5cab9b3f67fbf1bb7f18b6
2020-11-24 17:35:00 +00:00
Semyon Proshev 9335c066f5 Make parser stricter for assignment expressions (PY-33886, PY-36478)
Now it more follows original python grammar.

GitOrigin-RevId: f2b45554d16ff87d946950591f0e92fedcfdfaf0
2020-11-24 17:34:59 +00:00
Mikhail Golubev 91d49d6c87 i18n: Extract Python parsing errors, fix their capitalization and format
GitOrigin-RevId: a7374f1cb1358005b371fcfdeb743a24e04e1fbf
2020-08-17 16:32:09 +00:00
Mikhail Golubev ed4b1332dc PY-32864 Automatically merge f-string text tokens
It not only makes AST of f-string nodes simpler and more obvious to work with,
but, in general, is also better supported by various platform functionality that
assumes that raw text parts of string literals are not broken into multiple
elements.

GitOrigin-RevId: 931d1ea4c09d145e763aed839dcb4acbb3e43ec7
2020-08-17 11:12:03 +00:00
Lada Gagina 2e617b803c IDEA-CR-63687: PY-41305 Add PEP 614 support
Allows to use any expression as a decorator

GitOrigin-RevId: e92af1ebd2c4d7024971fd4542bfe52640faaa26
2020-06-17 00:30:49 +03:00
Semyon Proshev 5636d2ed7c Update tests after wrapping assigned value into parenthesis while mapping to targets (PY-40814)
GitOrigin-RevId: 74f47b126b61459383186d691a4bf3dfab09edda
2020-02-28 14:02:40 +00:00
Semyon Proshev 8f58988590 i18n
GitOrigin-RevId: c6b70355ca538e522a1b896f412c972fe7aa56e9
2020-02-13 16:19:54 +00:00
Mikhail Golubev be2d55e603 PY-32123 Ignore escape sequences in raw f-strings by adding special token type for their text
GitOrigin-RevId: 0b15201c60ac56daa45f22bb5ff3c1f8836efee3
2020-01-28 16:04:27 +00:00
Semyon Proshev 8d1b70c5bb Drop psi builder cache on pushing or popping parsing scope (PY-36167)
Since builder could cache something related to the current scope (e.g. token type)

GitOrigin-RevId: ffabda058dac874bd9187fa27d30b823f782fcf6
2019-11-07 02:40:58 +00:00
Semyon Proshev 121f06d991 Avoid parsing RHS of assignment expression as target (PY-33886, PY-36479)
GitOrigin-RevId: 127743a6386b8155ba131fa7f249c761598880e1
2019-08-13 17:04:49 +03:00
Semyon Proshev ba8411f567 Better handling of incomplete assignment expressions (PY-36479)
Create assignment expression even if its LHS or RHS is invalid.

GitOrigin-RevId: 6905a3b255f0c1fad576049265e39c0434f2d8e3
2019-08-13 17:04:49 +03:00
Semyon Proshev e13675f384 Fix parsing assignment expressions inside f-strings (PEP 572) (PY-33886)
Every expression on top-level inside f-string that could be considered as an assignment expression is actually a format expression.

GitOrigin-RevId: a375543c80d549d5c08166f33b401206ab31f8b8
2019-07-02 06:52:16 +03:00
Semyon Proshev ccc2156cf9 Add parsing for assignment expressions (PEP 572) (PY-33886)
Highlight expressions that are invalid by grammar or unacceptable in runtime
Highlight expressions in pythons < 3.8

GitOrigin-RevId: 89acec9db5b3a931da31c33778185e147240ec01
2019-07-02 06:52:16 +03:00
Lada Gagina 3b991b20ca PY-36009 Add support of '=' for debugging in f-strings
GitOrigin-RevId: 79314512860158a4c535103ee2ac9fee43d30d0d
2019-07-02 06:52:16 +03:00
Rustam Vishnyakov 123242c4b2 EditorConfig documentation test
GitOrigin-RevId: fd52ace3d7a32ecd02c2c5ab90e077967604c15e
2019-06-16 04:03:21 +03:00
Egor Zhdan c1813cfb52 Cleanup: NotNull/Nullable
GitOrigin-RevId: b8e892f32ea84c2115973155dba7127b892cc36e
2019-06-16 04:02:08 +03:00
Anna Kozlova 91f7445298 constructor reference: don't ignore constructor parameters during method reference inference (IDEA-185578)
GitOrigin-RevId: e836468e05db28157713e9edd3c70382f8ecdebc
2019-06-13 03:15:49 +03:00
Egor Zhdan 39d2d77155 Cleanup: NotNull/Nullable
GitOrigin-RevId: b8e892f32ea84c2115973155dba7127b892cc36e
2019-06-13 03:14:35 +03:00
Julia Beliaeva 3fee046d20 [vcs-log] cleanup RootCellRenderer
GitOrigin-RevId: bba216626193ac756cd133b8ae9bc4e577abea42
2019-06-10 04:10:14 +03:00
Eldar Abusalimov dcaeb8f8c7 OC-4061: ApplicationUtil: Make runWithCheckCanceled() return result
GitOrigin-RevId: 3aa9f23cc5097e644eddf82a4faca669759b4760
2019-06-10 04:09:35 +03:00
Semyon Proshev d7e8ebf1ef Parsing for positional-only parameters (PEP 570) (PY-35512)
GitOrigin-RevId: c568de8ebdb4f9b73cd5e2f9cb4a17184092ee22
2019-06-04 19:11:50 +03:00
Mikhail Golubev 6354daae42 PY-31442 Rename PyRichStringNode to PyStringElement with inheritors
so as not to cause confusion with ASTNode. Also additionally rename
PyLiteralStringElement to PyPlainStringElement, again, not to confuse
users with subtle "string literal" vs. "literal string" differences
in meaning.
2018-10-01 12:46:48 +03:00