Commit Graph

1282 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
Bernhard Geisberger
196d7126be [fleet] Don't refresh installed packages during fleet highlighting (FL-20595)
GitOrigin-RevId: 0b5b7f6828ba8ff5f5711e548670c11dd3bd15fb
2023-11-20 20:26:35 +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
250fc7f773 PY-59217 Fix dead lock RA+invokeAndWait in ViewHandler.invoke
The current solution is just a crutch
TODO: rewrite to UI DSL and model

GitOrigin-RevId: 6eda16e2d52444254f48813de151e3c1c77c7adc
2023-11-14 22:17:18 +00:00
Alexandr Evstigneev
bbdcd75b43 IDEA-337778 Added telemetry for python file lexing and parsing
GitOrigin-RevId: f45cf3438d76464be23afcbb8c85d8c244153397
2023-11-12 14:28:46 +00:00
Andrey.Matveev
fe1d064d41 PY-63273 Remove source from NAMEDTUPLE_SPECIAL_ATTRIBUTES
GitOrigin-RevId: f4744a3818835e14e4ce41034bec13f931a2aab6
2023-11-10 17:48:23 +00:00
Andrey.Matveev
8e825dfbbf PY-63273 Update versions in PyTypeShed
GitOrigin-RevId: 33ea19410a3a52acb38a06b630d5f306abb242e1
2023-11-10 17:48:23 +00:00
Vladimir Koshelev
fc2c9805c8 [python] unify access to named arguments in decorators for stubs and ast PY-62709
GitOrigin-RevId: ef095bd1186dc4c91662576cbf30ae7559804671
2023-11-10 16:24:46 +00:00
Mikhail Golubev
75aaa14404 Remove PyStringLiteralType.fromLiteral
It's sufficient to promote the type of string literals to Literal['content']
when a type containing a literal type (either Literal or LiteralString) is
expected, since Literal['content'] is always compatible with LiteralString.

(cherry picked from commit 3c9c0b1c451a17b7f56f3376d9e6cd493a770a73)

IJ-MR-112631

GitOrigin-RevId: 92e3ad2da4874e33af22c56d9dd38fd9c8ff871e
2023-11-07 22:10:44 +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
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
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
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
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
Nikita Ashihmin
d44ce30231 [bdt] BDIDE-5203 Spark(feat): Add context to PythonDocumentationQuickInfoProvider
GitOrigin-RevId: 32d5ecfccfccc88e00addddd0d813bf28277672a
2023-11-01 17:52:23 +00:00
Nikita Ashihmin
65f8b3a286 [bdt] BDIDE-5203 PySpark(feat): Add columns info to Hint Documentation
GitOrigin-RevId: 41a5912a85254c6ea53c8be1805884b0a2491718
2023-10-31 22:31:30 +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
Alexander Koshevoy
b56e3b9b47 PY-32853 Rewrite CondaExecutablesLocator.kt using NIO Paths instead of VirtualFiles
GitOrigin-RevId: e31e36a209c19d9ab26a0fd030ce130a8e732752
2023-10-23 00:47:10 +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
51854f80b3 "Method can be static" fix massive application
GitOrigin-RevId: ed296b85922a6814d5c6057b5cbc720f0c546e41
2023-10-20 19:12:56 +00:00
Mikhail Golubev
71b673ece6 [python] Use PyUnpackedTupleType in implementation of PyTupleType
GitOrigin-RevId: ce8f7f0ce4838dbd154500439326121c91732be5
2023-10-20 16:58:01 +00:00
Mikhail Golubev
15c37a5bad PY-53105 PEP 646: Split PyGenericVariadicType into PyUnpackedTupleType and PyTypeVarTupleType
TypeVarTuples, i.e. type parameters, such as *Ts, and unpacked tuples types, i.e.
concrete types, such as *tuple[int, ...], are two independent entities in the type
system. Keeping them both represented as a single type is confusing and introduces
a lot of bookkeeping for accessing their state and filtering out unpacked tuples in
every place where a type parameter is expected.

For cases where both types are applicable, and we need to distinguish them from regular
"non-unpackable" types, PyVariadicType marker interface was introduced.

Also, make the API names more consistent with the PEPs terminology: "unbound" unpacked
tuple types instead of "homogeneous" unpacked tuple types.

GitOrigin-RevId: be77eae46fd78512eaf74d5a9709faacc762e45f
2023-10-20 13:38:11 +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
ffda93c6fb PY-62641 Fix promotion of collection types to their versions containing literal type parameters
Previously, we incorrectly inferred generic list and set types parameterized with
types of each element of the corresponding collection literal instead of a union
of those. For instance, for [1, 2] we inferred list[Literal[1], Literal[2]] instead
of list[Literal[1, 2]].

GitOrigin-RevId: 6f222daee871137a5de5589429f78341704c5544
2023-10-20 13:38:08 +00:00
Mikhail Golubev
f66c17da9b [python] Add a couple of clarifying comments about matching of generics in PyTypeChecker
GitOrigin-RevId: ab43149c594dbb0d94c4a93b7285293fb87c2b4d
2023-10-20 13:38:07 +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
a493b99ba1 PY-53105 Fix problem with collectTypeSubstitutions add generic variadic vase to calculateGenericSubstitutions
GitOrigin-RevId: bae746ad263cddd88b7d889669a766a24f417358
2023-10-20 13:38:05 +00:00
andrey.matveev
a75c569022 PY-53105 Support TypeVarTuple
GitOrigin-RevId: f8160e9d802b09991daa710ed9a20f3e30d455da
2023-10-20 13:38:04 +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
Vladimir Koshelev
93a3c288f4 [python] remove duplicated util class
GitOrigin-RevId: b4011208ee1e8aaa529ee1b39304d393cdc1869a
2023-10-16 13:44:27 +00:00
Andrey Vokin
6072d9b0b0 DS-5773 Second closed brace is not completed
GitOrigin-RevId: 44acbac1018e4cfdad9036851075cdeba445cfb3
2023-10-13 13:36:07 +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
Konstantin Aleev
ad8c453d74 [platform] IDEA-331384 API: encapsulate TailTypes fields
GitOrigin-RevId: 5c33b3466c0c01832ed8b651a4eb651cf649847f
2023-10-11 13:47:40 +00:00
Vladimir Koshelev
7dc8c853c5 [python] move some stuff from openapi
GitOrigin-RevId: bc0a26fd9436a26c7e4b2be1cb0210b7179bf3bb
2023-10-10 08:27:58 +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
Konstantin Aleev
84f54ed97d [platform] IDEA-331384 API: deprecate constants in TailType class including those of type CharTailType
- rename existing TailTypes class to JavaTailTypes
- declare constants in new TailTypes class
- update usages

GitOrigin-RevId: 62484d4a67c291ff5da13fad223b841cb1855eac
2023-10-06 18:19:16 +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
Mikhail Golubev
927eca19f5 [python] Compare versions of module SDKs in PythonLanguageLevelPusher using a stream
Even though LanguageLevel enum items are already sorted by the corresponding
version, I decided to introduce a dedicated comparator to make sure that the
logic of isOlderThan/isAtLeast is used for compareTo, not the default order of
enums.

GitOrigin-RevId: f1d4845154c9b71e920e2b634ea6339643bf9467
2023-10-02 21:38:03 +00:00
Mikhail Golubev
8f10389294 [python] Use Supplier instead of deprecated Computable in PythonLanguageLevelPusher
GitOrigin-RevId: 7fb027247debcb11dadd99f0920a9c0ba1ab7153
2023-10-02 21:38:00 +00:00
Mikhail Golubev
2cee448e07 [python] Always iterate over distinct SDKs in PythonLanguageLevelPusher
GitOrigin-RevId: 286ce79b201f715e37bb5e1d5db708c1437d0e72
2023-10-02 21:37:57 +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
Anton Lobov
30fbdc68cb [fleet] python extract method for ranges done
GitOrigin-RevId: 120e57aafb311242a7e6696475edfa257fd86e47
2023-10-01 10:02:14 +00:00