Commit Graph

208 Commits

Author SHA1 Message Date
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
Mikhail Golubev
834084969c PY-40395 Report usages of classes inside type hints in a dedicated group
GitOrigin-RevId: ceceb43cc9c82a4831e5df9790a1689ee792edf4
2023-10-23 23:44:32 +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
Mikhail Golubev
a14c9ef92c PY-53105 Support PEP 646 and TypeVarTuples. Take 2.
The introduction of TypeVarTuples and the concept of unpacked tuple types made us
revise all the places where we match sequences of types in type inference.
For instance, when matching type parameters and type arguments for generic
specialization in:

* type hints, i.e. xs: MyGeneric[int, str] = MyGeneric()
* constructor invocations, i.e. xs = MyGeneric[int, str]()
* class declarations, i.e. class MyGeneric(Base[T1, T2, str]): ...
* type alias declarations, i.e. MyAlias: TypeAlias = MyGeneric[T, int]

as well as during type matching of all generic types, both normal non-variadic and
existing "built-in" generic variadics in the type system, namely tuples and
Callables.

Previously, this logic was spread across numerous places in PyTypeChecker and
PyTypingTypeProvider, all with their own subtle differences. The first attempt
of PEP 646 support put all the code for uniform matching of type parameters directly
in PyTypeChecker, significantly complicating its already arcane internals.
I've introduced a unified API for that called PyTypeParameterMapping.
It still retains some of the former quirks in form of its Option flags, controlling
in particular how we handle having some of the expected types unmatched
(imagine expecting MyGeneric[T1, T2, *Ts] and receiving MyGeneric[int]),
but I'm planning to gradually eliminate this conditional logic.

The same class is now also responsible for matching parameter types of callables
that already allowed to fix some of the known problems, such as ignoring their
arity (PY-16994), but I'm going to extract a separate API entity for that, since
matching of callable signatures is a much more complicated task involving
compatibility of different types of parameters (positional-only, keyword-only,
defaults, varargs, etc.).

Another positive side effect of these changes is that substitution of type
parameters during type inference became more consistent, and we no longer lose
useful type information by replacing all unbound type parameters with Any. It's
particularly visible in type checker errors where we stopped dropping unbound type
parameters from messages about mismatched parameter-argument types.

Among other improvements in this changeset are proper scoping for
TypeVarTuples, consistent with other type parameters, and recognizing TypeVarTuples
and unpacked tuples in types of *args parameters in function bodies, e.g.
`*args: *Ts` translates to "args" parameter having the type `tuple[*Ts]`.

Confusing PyNoMatchedType used only for reporting of missing arguments for *args
parameters annotated with unpacked tuples in the type checker inspection, e.g.

def f(*args: *tuple[int, str]): ...
f(42)  # a type checker error about a missing argument for str

was also removed from the type system in favor of a simpler approach with handling
such errors directly in the inspection. We might need such a general type in
the future, but it has to be well thought-through.

GitOrigin-RevId: 63db6202254205863657f014632d141d340fe147
2023-10-20 13:38:06 +00:00
andrey.matveev
a75c569022 PY-53105 Support TypeVarTuple
GitOrigin-RevId: f8160e9d802b09991daa710ed9a20f3e30d455da
2023-10-20 13:38:04 +00:00
Vladimir Koshelev
158bc649f1 [python] implement package name collectors for imports in file and completion
Also, this commit changes the behavior of PyPIPackageUtil, now only one package per name is supported. Motivation:
- it complicates the logic in all usages of the mapping
- There are only 3 cases when it's applicable and in all cases the second package is abandoned.

GitOrigin-RevId: 80fb1e0d28369bdfeb64f6b928ed1b543165d1de
2023-10-13 09:51:16 +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
Louis Vignier
a7d33eaba6 [properties] Cleanup: fix extra space before ellipsis
#IDEA-334322 Fixed

GitOrigin-RevId: 7114856688771756bae7694542abac6e5ad1177d
2023-10-07 10:54:04 +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
9249e0a15c PY-61856 PEP 695 Type Parameter Syntax: Code compatibility inspection and unsupported features annotator
GitOrigin-RevId: 164a07daff1059ac1a421e1a883168924f82559e
2023-09-28 15:05:34 +00:00
Daniil Kalinin
8b217ed53a PY-61853 PEP 695 Type Parameter Syntax: Parsing
GitOrigin-RevId: 286b53bb4e69cf1deb58dc75f41652e6a12a3af3
2023-09-15 16:04:41 +00:00
Egor.Eliseev
540f24faa4 PY-34498 Add an inspection for pytest fixture that is not passed to test parameters
Report warning if a fixture is used without being passed to test function parameters or to
`@pytest.mark.usefixtures` decorator.


Co-authored-by: Denis Mashutin <Denis.Mashutin@jetbrains.com>


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

GitOrigin-RevId: 28d0711b99ab7ae180f672306dd4ab8a81f1feec
2023-09-04 09:53:07 +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
Sergey Karpov
c0842a6fde [pycharm] Squashed commits. PY-52478 Improve the names of quick fixes for "Unresolved references" and "Non-optimal list declaration"
(cherry picked from commit bce089714657aef8634ffb9c58da57fdb576b297)

IJ-CR-112218

GitOrigin-RevId: 8857c2951e44a1e9d0b54af1eb7c584f64fbc40d
2023-07-31 16:31: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
Mikhail Golubev
d22b8b00b9 [python] Extract a common quick fix for unresolved package problems
GitOrigin-RevId: a1db8823a2fc83424431d975e1820b415895cc7a
2023-07-06 10:41:32 +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
Natalia.Murycheva
0d53aa47df DS-4878 Pandas-specific-quick-fix-replace-listdf.col.values-to-df.col.tolist
Add new intention and a corresponding quick fix for the usage pd.Series.values property from pandas library.

^DS-4878 Fixed

Merge-request: IJ-MR-106089
Merged-by: Natalia Murycheva <natalia.murycheva@jetbrains.com>

GitOrigin-RevId: 0c8dc40b09ee2d95ecd8ded532f31f5ef4a7740f
2023-05-13 20:44:29 +00:00
Natalia.Murycheva
10f22bb2e2 DS-4558 Quick fix to split a cell for statement has no effect inspection
Added a new Extension Point for corresponding quick fixes for "Statement without effect inspection." Added QF for Jupyter notebook case and Python file with cells. This QF splits cell just right after the statement without effect

^DS-4558 Fixed

Merge-request: IJ-MR-104455
Merged-by: Natalia Murycheva <natalia.murycheva@jetbrains.com>

GitOrigin-RevId: 7773895cf1ebd6d4e8d56b41e335ec8b97ca5d78
2023-05-03 15:03:06 +00:00
Louis Vignier
1869ec9da6 [codeInspection] Fix python inspection descriptions
GitOrigin-RevId: 56876a5dd073a06c3fcc92f63ed1f5674830bc25
2023-04-28 13:13:25 +00:00
Irina Fediaeva
3afa041f1b PY-32067: Highlight 'await' outside async functions as errors
GitOrigin-RevId: 9862d18848b3a826ba11e9c0e15e56a2c94bcc9e
2023-04-19 20:42:02 +00:00
Daniel Schmidt
abedaa8420 PY-39352 - use the more accurate term "CapWords" instead of "CamelCase"
closes https://github.com/JetBrains/intellij-community/pull/2403

GitOrigin-RevId: 09122e4c36fc6f40d9b79869152d0fd9f2fdeeda
2023-04-17 14:52:30 +00:00
Irina Fediaeva
bb882b63f5 PY-55118: Syntax highlighting for definition signatures in Quick Documentation
GitOrigin-RevId: b8a27a048772a0af7fcc36a9cba0d308e0ace8cc
2023-02-10 22:44:22 +00:00
Tagir Valeev
7a33190f27 [inspections] testOptPaneSanityChecks: more tests for labels
GitOrigin-RevId: 6420065945442503db628555d1f8ea14c6db2b42
2023-01-30 10:42:04 +00:00
Irina Fediaeva
252e4c1684 PY-56609: Refactoring in quick documentation
Replace usages of appendRaw by append

GitOrigin-RevId: 3ee71857898c3303a5c2e96939ab1f9fb91670e0
2023-01-23 13:39:05 +00:00
Irina Fediaeva
bd1c830040 PY-56609: Refactoring in quick documentation
Remove ChainIterable usages from quick documentation and replace with HtmlChunk/HtmlBuilder.
I18ize some fragments.

GitOrigin-RevId: c9b1197efcb17de92361426759a7840ee1be8e4b
2023-01-23 13:38:53 +00:00
Tagir Valeev
fa3cf18c12 [inspections] OptPane: use stringSet
GitOrigin-RevId: 7f3ba5c990d8aa173d8edf3a38bb21543c26d0fa
2022-12-21 19:22:09 +00:00
Alexey Belkov
390ba59bc2 Fix spelling of "quick-fix" phrase in messages
It should be hyphenated: https://www.jetbrains.com/help/idea/resolving-problems.html

GitOrigin-RevId: a3cc01babc32c3edfbe59594fa3756a415cc169b
2022-12-07 15:26:37 +00:00
Irina.Fediaeva
22327f9518 PY-46164: Rename PSI bundle for a link to copied documentation
GitOrigin-RevId: e209e34c875fcf9603c0e967b3429ed41e792770
2022-11-15 21:16:01 +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
andrey.matveev
d0e0488fe6 PY-40797 Fix problem with inline string to f-string
GitOrigin-RevId: dbc2206fa2338e2b6a2552a0ca76cb4064425505
2022-11-03 17:30:23 +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
andrey.matveev
cad1138e59 PY-53104 Support PEP 673 typing.Self type
GitOrigin-RevId: 8efc65725580510dc3e9a93e1242e1a69032c8f1
2022-10-19 09:45:15 +00:00
Irina.Fediaeva
cb8edc622b PY-33341, PY-56416, PY-28900: Render attributes and init params description in the class documentation
PY-33341: Now we render the “Attributes” section in the class documentation, it also allows to describe inherited attributes. (Previously we didn’t render it at all)
PY-56416: In the attribute documentation popup we are able to render attribute description from class docstring. (Previously we took documentation only explicitly from attribute one-line docstring)
PY-33341: We render the “Parameters” section in the class documentation for init parameters, described in the class docstring. (Previously user couldn't use class docstring to describe init parameters)
PY-28900: For the init parameter documentation we take the description from the class docstring if init doesn't have its own docstring. (Previously we took parameter description only from init docstring)

GitOrigin-RevId: d67bf49c72cf7a3634805a6e310c943f1ea848d1
2022-10-07 14:42:01 +00:00
Pavel Karateev
a47cf9f44e PY-55920 Suggest python-slugify for installation
GitOrigin-RevId: 0ef316336587d73cd2b79f6862635900ecde5fa6
2022-09-05 20:03: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
Mikhail Golubev
84c48c48a9 PY-47532 Support new API and namespace of "attrs" package
GitOrigin-RevId: a8a0f909b21cc9f3b95a7b823452599374a943a9
2022-08-18 16:13:12 +00:00
Daniil Kalinin
f0687cf116 PY-54540 No error when ClassVar contains type variables
Inspection that checks if ClassVar contains type variables which is not allowed

Tests for it

Merge-request: IJ-MR-25493
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: 0fcf81aca7416c04488cf389aba107588561554d
2022-07-26 12:16:31 +00:00
lada.gagina
6bdc3d4237 PY-53611 Add support of Required and NotRequired TypedDict type specifications (PEP-655)
Makes it possible to mark individual TypedDict keys as required or not required, covered in [PEP-655](https://peps.python.org/pep-0655/)

GitOrigin-RevId: 6567fd1009430e37f32924eb29ab8b4a1a17f315
2022-06-21 20:29:34 +00:00
Elizaveta Shashkova
6e383650ca PY-53776 Support the syntax changes of PEP 646 Variadic Generics
GitOrigin-RevId: 6ee5939eff1c0503132b013c6469de00b50b2d86
2022-05-30 09:40:36 +00:00
andrey.matveev
a50487b100 PY-50403 PY-50404 Analyse param spec container parameters
GitOrigin-RevId: 2b7653d2b52788673fcf61cdb038620162c232da
2022-05-25 13:58:22 +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
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
andrey.matveev
a66dea2997 PY-50401 Impl checking name argument in ParamSpec
GitOrigin-RevId: 655026dceea03b1697e5d39ce897f2ef1f25948c
2022-05-06 12:15:27 +00:00