Commit Graph

6298 Commits

Author SHA1 Message Date
Mikhail Golubev
910a39d81f PY-64124 Match expected positional- and keyword-only parameters with regular parameters
The original false positive was caused by the protocol NestedSequence in matplotlib
defined as:

class NestedSequence(Protocol[_T_co]):
    def __getitem__(self, key: int, /) -> _T_co | NestedSequence[_T_co]: ...
    def __len__(self, /) -> int: ...

which was used to annotate parameters of matplotlib.pyplot.plot and was considered
incompatible with the builtin list.

Skipping positional- and keyword-only parameter separators of the expected callable
is a workaround until we have a comprehensive mechanism for matching signatures.

GitOrigin-RevId: 93d8bb4c6c4405d0e24b5f98152a461691f6197e
2023-11-23 00:51:33 +00:00
Ilia Zakoulov
caa89a719d PY-64088: Provide onExecuted callback to CommandExecutor and implement DjangoStartAppExecutor
GitOrigin-RevId: ed27d076706dc1d100a8d7d7a03a68818996b36e
2023-11-17 22:58:25 +00:00
lada.gagina
75b1ecd244 [python] Cleanup supported/unsupported versions xmls
- Drop support for python 3.5 & 3.6 in compatibility inspection
- Fix and remove some outdated tests
- Remove xmls for long-unsupported python 2.6 & 3.5
- Regenerate versions.xml
- Remove mentions of OS-specific modules

GitOrigin-RevId: 3265dd1de8a4f7a41119e10c95bb705ca5845efe
2023-11-17 18:57:31 +00:00
Daniil Kalinin
6d0787f084 PY-64127, PY-64128 fix false positive "Invalid statement in TypedDict definition" and "Value must be a type" in TypedDict declarations with new-style type parameters syntax
GitOrigin-RevId: d1caaf191ceff7bb03cd5a158242e35aacbeeefc
2023-11-17 13:09:29 +00:00
Andrey.Matveev
db5c251333 PY-63273 Fix tests
GitOrigin-RevId: 6c26cc44b2ab1080cb3c1d61b7a7053622ce0e51
2023-11-10 17:48:24 +00:00
Andrey.Matveev
52229081e9 PY-63273 Fix tests related to TypeVar constructor
GitOrigin-RevId: 2608401a0a9b35d458b923ccb46d2e140e9abedf
2023-11-10 17:48:23 +00:00
Andrey.Matveev
af4f8b8015 PY-63273 Fix PyStructureViewTest
GitOrigin-RevId: 2106007f7e2a1bf9e82df14b806723cdb4dbee0e
2023-11-10 17:48:23 +00:00
lada.gagina
be82cf6646 PY-61137 Accept LiteralString if expected is a TypeVar with LiteralString as a bound
(cherry picked from commit 5de62a9e91dbfa74b5077671858f96e446e9d121)

IJ-MR-112631

GitOrigin-RevId: 829184b6a204609d67cf4c668eb1125c46fa2d84
2023-11-07 22:10:40 +00:00
Mikhail Golubev
4f681032ed "Erase" LiteralString when mapping a type to a type parameter
(cherry picked from commit 2c5372206aabfbb02277c2fdb3572fc01241c8ca)

IJ-MR-112631

GitOrigin-RevId: 060cc384418912fee217b2930a4c0f46ef1ed53e
2023-11-07 22:10:37 +00:00
lada.gagina
df7b4cc93e PY-61137 Fix Literal & LiteralString inference for conditional expressions
(cherry picked from commit d0dae3dc8a593806d0218b02a130ac545ec6ca99)

IJ-MR-112631

GitOrigin-RevId: f4598c40b4e078e8001f66655b532b45b9b71dae
2023-11-07 22:10:33 +00:00
lada.gagina
4061c6e187 PY-61139 Do not infer LiteralString for parameters with str default value
(cherry picked from commit 80992fa5d2d3e393326e4f469fe3bd6472f70643)

IJ-MR-112631

GitOrigin-RevId: ebbe6c433c4536660c7ccbe8462f16667a75c434
2023-11-07 22:10:30 +00:00
lada.gagina
ec805fe401 PY-61137 Infer LiteralString only when it is expected type
(cherry picked from commit b5ca959becdc8aaf82a2baac5bca6128fdef2b41)

IJ-MR-112631

GitOrigin-RevId: f922fd60c3586b33dc26c1a1c69c50c8bd91cbb9
2023-11-07 22:10:26 +00:00
lada.gagina
ad5b55918e Revert tests with over-inferring LiteralString
(cherry picked from commit 0c92e1c64362e2834b01b4e0bcbcedfefe4febe0)

IJ-MR-112631

GitOrigin-RevId: 233abfde16b19e96c5bc39c77eef1a240aa1b3e8
2023-11-07 22:10:23 +00:00
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
Daniil Kalinin
ac6316198f PY-61857 Implement PyTypeParameterListAnnotator for PEP 695 type parameter syntax
It reports such cases:
* Duplicated type parameter names in type parameter lists
* Wrong number of type var constraints (one or zero) defined with new-style PEP 695 syntax
* Use of constraints for ParamSpec and TypeVarTuple type parameter kinds

GitOrigin-RevId: e0e8e7eb4dcef0c1b56ea49a3527666e3c713d86
2023-11-06 19:59:18 +00:00
Daniil Kalinin
eb58a3805e PY-61883 PEP 695 Type Parameter Syntax: Make PyTypingTypeProvider aware of the new-style type parameters and aliases
Inherit PyTypeAliasStatement from PyQualifiedNameOwner to re-use type aliases stack in PyTypingTypeProvider

Various tests for the changes above

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

GitOrigin-RevId: 242427c6f84c05ec48c94085f20675b8e30f8625
2023-11-06 19:59:18 +00:00
Daniil Kalinin
0ca9ba4a99 PY-62608 Store info about type parameter kind (TypeVar/ParamSpec/TypeVarTuple) inside PSI stubs
GitOrigin-RevId: 80aa6d67e32a0e7e2a7e8ed53f72288831e9dccf
2023-11-06 19:59:18 +00:00
Daniil Ovchinnikov
24659c0cff migrate ProgressSink usages to RawProgressReporter and remove ProgressSink
GitOrigin-RevId: 671e9b9ec7a703c80b91b15a793b03e88d6e21fe
2023-10-23 21:10:54 +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
Tagir Valeev
c3326028e3 StringBuilder -> String converted
GitOrigin-RevId: 1e5434c8a5624f9cbea15933d32b87d61b27650b
2023-10-21 17:44:28 +00:00
Tagir Valeev
2e8756c54d [python-tests] Fix warnings
GitOrigin-RevId: 01ee3e5535b25dc0016c351763f87c5597a3c1a9
2023-10-21 17:44:21 +00:00
Mikhail Golubev
b0b7d9aacd PY-53105 PEP 646: Render unpacked tuples as *tuple[T1, T2, ...], not as *(T1, T2, ...)
I prefer the notations used for defining a type and rendering it in the IDE not to diverge,
unless there is a strong incentive to do that. Doing that for Callables is already forcing
us to use two different type renderers for Quick Documentation and generating type hints.

GitOrigin-RevId: f6340182bad60d6a7e94156aadc0f17440ee59d5
2023-10-20 13:38:10 +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
Bart van Helvert
edbbeaa330 Fix test cases without tests
Either by using `@Ignore` or making open class abstract

GitOrigin-RevId: bae4d594cf8c326d10dbfffc730f0eeefdba65b1
2023-10-19 23:20:53 +00:00
Egor.Eliseev
41b83761ee PY-60034 'Slow operations are prohibited on EDT': sdk.PythonSdkUtil.findPythonSdk
Merge-request: IJ-MR-116812
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: a9c0ec6b0462cf2c3401dd50140b4752da9e0b42
2023-10-17 18:57:48 +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
caf1082077 [python] Remove instructions for parameter defaults and return type annotations from functions CFG
Both of these are evaluated in the outer scope, e.g., in a scope of a containing class or a module,
with the corresponding instructions already processed there, and were duplicated in the CFG
of function bodies.

GitOrigin-RevId: 4460cbef6446a311f0ab15ffe3407bfbb73286e2
2023-10-16 23:42:44 +00:00
Nikita Kudrin
5f15fa3f42 [test framework] AT-107 Adding dependency on intellij.tools.ide.metrics.benchmark to publish metrics
GitOrigin-RevId: aaeb67a13dab0038e8f8e8ec6ed7d683d4dfe5d3
2023-10-16 23:23:34 +00:00
Vladimir Koshelev
4b88faf6f6 [python] ensure that a valid current file is passed to PyInspectionTestCase
GitOrigin-RevId: f2e3530c0aa0a5edc5da3716aef90a2966397d88
2023-10-13 09:51:23 +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
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
2e8e817447 PY-63371 PY-63372 PY-63373 Recognize type alias names in their definitions as targets for actions
In particular, for Rename and Go to Declaration or Usages.

GitOrigin-RevId: 760a28b3a2a2b22022e938d7b4b96729cd7f7dc2
2023-10-05 22:02:24 +00:00
lada.gagina
06145574e5 [python] Initial requirements.txt support (PY-58598)
GitOrigin-RevId: 724b87887814e41e9c2e897e97143bd5b3396c0e
2023-10-05 21:18:09 +00:00
Daniil Kalinin
c2576bc1e7 PY-63357 Fix false positive "Local variable might be referenced before assignment" in function declarations
GitOrigin-RevId: bdbc32942e19d63397c4176c700a1c4ae7968b62
2023-10-02 10:20:31 +00:00
Mikhail Golubev
7f152c983f PY-59594 PEP 701: Make the Inline refactoring aware of the new f-string grammar
(cherry picked from commit 4fe1044cadef561f369a77ddbe98ff29e6fcc5a2)

IJ-MR-115763

GitOrigin-RevId: 5cf7b9d61ea546e0a9e30c0c8a1d432d79e0738e
2023-09-29 09:33:55 +00:00
Mikhail Golubev
0d34a0e88f PY-59594 PEP 701: Make the intention for flipping string quotes aware of the syntax
(cherry picked from commit a62f78cfdee24eccf3fcf2d341807565f26d2fbd)

IJ-MR-115763

GitOrigin-RevId: 059a289a9006d592a88a677137647c0660c68fc2
2023-09-29 09:33:49 +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
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
65cc3ddfd0 PY-61877, PY-61878 PEP 695 Type Parameter Syntax: Control flow for type parameters and type aliases
GitOrigin-RevId: 2db381cbb97891296bae09e48c17b46eefa57a04
2023-09-28 15:05:31 +00:00
Daniil Kalinin
1c5b0c5ac3 PY-62608 PEP 695 Type Parameter Syntax: PSI stubs for type parameter lists and type aliases
GitOrigin-RevId: b8707b4677519bab5bcf922c9747eb8388e3157b
2023-09-28 15:05:30 +00:00
Mikhail Golubev
a639a793c6 [python] Better failure messages for Python lexer tests
GitOrigin-RevId: d73a4cd02768912098206ea8fbc1b77973fe97db
2023-09-28 11:39:15 +00:00
Vladimir Koshelev
60090602b4 [python] treat as bool type guards in return types PY-62476
GitOrigin-RevId: 0b59fd99aeaece087837858fb13376370d0d225b
2023-09-19 12:11:20 +00:00
Vladimir Krivosheev
b67de4a4b0 IJPL-238 remove the unnecessary usage of commons-lang library (part 3)
GitOrigin-RevId: dec81af8deb5d9b396e9150538bdca1d951b1d80
2023-09-15 20:50:02 +00:00
Daniil Kalinin
3a70f1d22d PY-61854 PEP 695 Type Parameter Syntax: Formatting
GitOrigin-RevId: 272f956033d82626d7cf689aa561cdeab3f951da
2023-09-15 16:04:46 +00:00
Daniil Kalinin
4b6848cb9f PY-61855 PEP 695 Type Parameter Syntax: Highlighting
GitOrigin-RevId: 498ab5e3a697c2eb616ae3d0820f99c480596306
2023-09-15 16:04:43 +00:00
Daniil Kalinin
8b217ed53a PY-61853 PEP 695 Type Parameter Syntax: Parsing
GitOrigin-RevId: 286b53bb4e69cf1deb58dc75f41652e6a12a3af3
2023-09-15 16:04:41 +00:00
Daniil Kalinin
067452815f PY-20861 Python support with the Move Element Left/Right feature
Merge-request: IJ-MR-111447
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: a4fbe9d1a8634a7ad8f0893266e26738be993cea
2023-09-15 11:11:04 +00:00
Vladimir Krivosheev
125c41869b IDEA-332023 cleanup
GitOrigin-RevId: bae557ac0e0a4ef66918cb6c1d0118b6f0dcf615
2023-09-10 18:20:42 +00:00