Commit Graph

2591 Commits

Author SHA1 Message Date
evgeny.bovykin
40afa47531 PY-86902 Respect positional and keyword containers in PyTypingTypeProvider.getReferenceType
GitOrigin-RevId: ec3dee03096df46e9a461cc49ae929463f859f4c
2026-02-12 13:10:01 +00:00
Daniil Kalinin
6e2c7614ca PY-79067 Allow creating PyCallableType directly with PyCallableParameterVariadicType instead of wrapping it in the list of callable parameters
This refactoring allows simplifying and unifying logic whilst calculating substitutions for callable types and its matching in `PyTypeChecker`

GitOrigin-RevId: e61bd1f6cf19539b0a66ff2e3e47164aec0c0aa1
2026-02-12 10:45:05 +00:00
evgeny.bovykin
1ed32bf1d7 PY-42057 Only clarify resoled method call for property if it's a getter
For setters and deleters, this logic is redundant and leads to false-positives

GitOrigin-RevId: 0aff689846124830ea7186127593dbcc98f6eca3
2026-02-11 23:12:31 +00:00
Andrey Vokin
1856f3060f PY-87354 Pyrefly: support parsing typing.Callable, typing.Optional
For these symbols pyrefly returns non-qualified name that must be resolved further. From performance point of view it's better to specialcase them.

GitOrigin-RevId: 0fa4e85f03ef9df197ccfeef49c92b0118d70dab
2026-02-06 13:56:43 +00:00
Petr
32512f6abb PY-86957 Use PyTypedDictType.declaration as the exclusive source for hashCode/equals
GitOrigin-RevId: bc78e4a02a24c6d3fca8bbe6244e3916be377cb2
2026-02-05 13:53:47 +00:00
Petr
09eb7fe7a9 PY-86957 Improve naming and inline single-use methods in PyTypedDictTypeProvider.kt
GitOrigin-RevId: 48b3ae06d40b37ff066f7e160ff29439cd5f642d
2026-02-05 13:53:47 +00:00
Petr
e54c7dcde0 PY-86957 Remove redundant duplicate check
GitOrigin-RevId: 94144a9d6dfd2aabb153e8f5f5c3bbd1e3f95daa
2026-02-05 13:53:47 +00:00
Petr
353c0460ff PY-86957 Eliminate dead code in PyTypedDictTypeProvider and PyTypingNewTypeTypeProvider
The `resolved` parameter in `PyTypingTypeProvider.getTypeForResolvedElement`
is never a `TypedDict(...)` or `NewType(...)` call expression. The corresponding logic handling these cases is unreachable.

GitOrigin-RevId: 1270647014962e403b0620770f5c73700ca9ac52
2026-02-05 13:53:47 +00:00
Petr
1c22bf5592 PY-86957 Use expression body for simple functions (PyTypedDictType.kt)
GitOrigin-RevId: 29f493aa8d09c5fb7fabe5624e094afff586b659
2026-02-05 13:53:47 +00:00
Petr
d95f312a98 PY-86957 Delete PyTypedDictType.definitionLevel (duplicates base isDefinition())
GitOrigin-RevId: d970af3a2b4daded52c6d12bb39d86392cffe642
2026-02-05 13:53:47 +00:00
Petr
80d9de399f PY-86957 Delete unused PyTypedDictType.ancestors
GitOrigin-RevId: f1d9d8ee34a06e1cf990ed724260f79ea49f58ea
2026-02-05 13:53:47 +00:00
Marcus Mews
d6402476dd PY-87340 AIOOBE: PyExpectedTypeJudgement.getElementTypeAtTupleIndex()
GitOrigin-RevId: 96f94b3827d5247d94108d945999d9c00c139a79
2026-02-05 10:15:37 +00:00
Leonid Shalupov
c8cba92f81 IJI-3282 Optimize imports (2)
GitOrigin-RevId: a9977be5b80a96b658299f0385bbc6eb87621d17
2026-02-05 09:01:00 +00:00
Azim Akhmadjonov
d3306b960f PY-76899 Conformance test failure: dataclasses_transform_field
GitOrigin-RevId: 83dbf7add2b63b592a68e23182c22090f74f4f5d
2026-02-04 11:15:02 +00:00
Azim Akhmadjonov
6170b77faf PY-49946 fix: correct handling of KW_ONLY marker in dataclasses fields order check
GitOrigin-RevId: e57fb14748a631069169b6a121530053c6c604a6
2026-02-04 00:10:26 +00:00
Ilia Zakoulov
6e2d9cc90b PY-84031: Implement PyExternalFilesIndexService to index external files.
Non-project files by default are not indexed, do not have a module and do not have an SDK.
`PyExternalFilesIndexService` is resposible for adding a custom entities to the workspace model.

Space-RevId: dd7c50009e56dea0d69914c9f7f1524c7e77fe20

GitOrigin-RevId: cdfa2a578a01431fb9e0a06ce820c1d9b0f3fc0d
2026-02-03 23:35:47 +00:00
Mikhail Golubev
7ef55b2554 tests [python]: Add a fixme test for an unsupported case in PyExpectedTypeJudgmentTest
GitOrigin-RevId: a7e1b45b044ee15b7a84867a60e1787bb50d602b
2026-02-03 18:51:44 +00:00
Aleksandr.Govenko
da873ac92b PY-85990 [python]: unified logic in PyCaseClause and PyTypeAssertionEvaluator about exhaustiveness of match statement
Also, some small fixes here and there to ensure it works correctly

Space-RevId: 90f4b41c0eca9aae4c49841d756f7c96f805fcff

GitOrigin-RevId: 844c13869fb113df46537c4a644dbbfb8ba8c977
2026-02-03 18:14:34 +00:00
Aleksandr.Govenko
43c455cbb0 PY-83370 False positive "This code is unreachable" after isinstance check for subclasses
Space-RevId: a0d0d8780b3c7d2fc6c895e4d7f2fb5c76f680ad

GitOrigin-RevId: b0af91fef3a07bb86ce179d0ec3ba19c2bf58d9a
2026-02-03 17:03:56 +00:00
Andrey Vokin
fb7e584af5 PY-86493 performance optimisation
GitOrigin-RevId: c3e746f880f1eaf2af290d9cf082ea2086748fa7
2026-02-03 16:53:07 +00:00
Aleksandr.Govenko
3e0b2da403 PY-85595 Propagate Ref<PyType> from getReferenceTypeFromProviders to distinguish between null and explicit :Any typehint
Space-RevId: c6db6c041ea4a66f8c6d54764725bb7e4ab56653

GitOrigin-RevId: 011751c7b02da2c198ea3b8ffed7703ae6659e1c
2026-02-03 13:32:32 +00:00
Morgan Bartholomew
428635056c PY-87273 type representation: use Ref<PyType?>?
GitOrigin-RevId: fa2009fe63f9ce80a3fcb6b71746761f51d851db
2026-02-01 11:27:33 +00:00
Leonid Shalupov
188b7ef96f IJI-3282 Optimize imports
GitOrigin-RevId: 3b5c00d8ff20b8d0bb6005bc450921085d2da9b2
2026-01-31 17:03:42 +00:00
Vladimir.Koshelev
52d9e31d63 PY-87022 [python]: try to work around the fact that sdk might live longer than a project, thanks to ProjectJdkTable
GitOrigin-RevId: 075130300669d859e53ba4c61fe66555ae56294c
2026-01-30 21:49:04 +00:00
Vladimir.Koshelev
8762304f24 PY-87020 [python]: use PSI resolution for framework detection
GitOrigin-RevId: c85f2ac367c38f70ebc5d6cfcf79d94517819d0a
2026-01-30 21:49:04 +00:00
Nikita Paniukhin
2a4abac0b3 [python] PY-86315 Infer type for import alias
GitOrigin-RevId: 88dfacfffc98f680906fb7a316dcd1359a04410e
2026-01-30 20:19:39 +00:00
Morgan Bartholomew
c7435bdc99 PY-87182 type representation: fix issue with single star parameter
GitOrigin-RevId: aa60094e6fbb8cc4a9e0c129accc917b7933c7a4
2026-01-30 07:04:49 +00:00
Max Medvedev
4176c92f12 IJPL-207762 get rid of deprecated ussages of CompletionConfidence in monorepo
GitOrigin-RevId: 23607c5dd921421af31933c69e56b5c9931d8162
2026-01-27 15:23:16 +00:00
Morgan Bartholomew
30994eb91a PY-87102 fix Any detection in type annotations
GitOrigin-RevId: 825d00aa8a57af3c3120ea760e3c53da44c53fd0
2026-01-27 11:31:23 +00:00
Mikhail Golubev
abe26b050d PY-76922 Add a barebone implementation of PyIntersectionType
For the time being, it's possible to declare an intersection type
as "A & B", though it should be either wrapped in a string literal,
used with `from __future__ import annotations` or with Python 3.14+
to avoid runtime errors (and there still be warnings about unresolved
`type.__and__`) and it's not possible to generate a type hint for them.
At least until intersection types are added to the typing specification,
or we adopt something similar to "ty_extensions".

Specific use cases, such as using intersections for type narrowing,
`super()`, overloads, etc. will be addressed separately.

Space-RevId: 16c28a020f0b102f54f56ae25b5c25dc143fd76d

GitOrigin-RevId: d2581559197819fbbc49e4f75b62aa2962924938
2026-01-26 17:03:32 +00:00
Mikhail Golubev
c003940340 PY-87012 Prohibit fully quoted RHS values in legacy implicit type aliases
So that `Alias = list["int | str"]` is valid, but `Alias = "int | str"` is not.
Writing `Alias: TypeAlias = "int | str"` (explicit type alias), however, is fine.

This behavior is enforced by the conformance test suite, see aliases_implicit.py.

Previously `PyTypeHintsInspectionTest.testImplicitTypeAliasesMultiFile`
passed "by accident" because we didn't consider the string content of
`BadTypeAlias14 = "int | str"` a valid type hint. Properly recognizing
union types in quotes made the test fail, even though the original rule
has nothing to do with union types themselves.

Adding a test on the new behavior revealed several other problems.
First, in PyTypingTypeProvider we completely bypassed well-formedness checks of
`PyTypingAliasStubType.getAssignedValueIfTypeAliasLike` calling directly
`PyTargetExpression.findAssignedValue` in files where AST access was allowed.

Second, `PyTypingAliasStubType.VALID_TYPE_ANNOTATION_ELEMENTS` didn't include
starred expressions, so all type aliases containing unpacked TypeVarTuples
(e.g. `*Ts`) were considered illegal. It broke detecting type parameter scopes
for implicit type aliases in `PyTypingTypeProvider.getTypeParameterScope`, where
`PyTypingAliasStubType.looksLikeTypeHint` is used.
Addressing that also made a correct generic type to be inferred in an existing test
`PyTypingTest.testGenericVariadicsIntersectsSameName`.

Space-RevId: 9629e7e50e82c1df863bd0fe115596e9ed48afed

GitOrigin-RevId: bc0eecfcdaf14d7f2eb53d79950a53fae0d2d273
2026-01-26 17:03:32 +00:00
Mikhail Golubev
10547473f8 PY-87012 Recognize union types in quoted old-style type aliases
Use a more permissive regex used for language injections inside type hints
to recognize old style type aliases to be saved in PSI stubs and valid
type hints.

Space-RevId: 3ce489544374c8764db6447438cc3b5f5d2d78cd

GitOrigin-RevId: 776ead0ca9580dbcc6874a84791550289a6f3a9a
2026-01-26 17:03:31 +00:00
Nikolay Chashnikov
6bfcc8920a cleanup [python]: remove unused duplicating PyTypeTokenTypes class
The class with the same qualified name is present in intellij.python.parser module, so having a duplicating one is confusing and leads to problems in scripts which analyses class files.

Space-RevId: f2baabd8ed6d66be239394b6c18558da1d3de8ff

GitOrigin-RevId: 379ded2168da297d0308da6523f5ae6d27f9b417
2026-01-23 18:22:29 +00:00
Morgan Bartholomew
dc406af601 PY-86755 type representation: support type parameter list
(cherry picked from commit fb1285b85145e3fcf43a7b75a2eaadbd00245f7f)

IJ-MR-188808

Space-RevId: fc01b7557c603f0c07a7e2d17f6d1fe0c7b75c69

GitOrigin-RevId: 440c1e6a47d31a2f1d708f304fb8caa1b33443bb
2026-01-23 14:40:59 +00:00
Petr
e4db3b24ad PY-86957 Preserve PyType graph topology when cloning
Space-RevId: 2d0a7408648865f8654fb83aab1ffc20ef400cf1

GitOrigin-RevId: 060a7848a120c1b323a15be6ec14b178c0c5fcbb
2026-01-22 21:52:47 +00:00
Petr
613ab90f97 PY-86957 Use identity comparison when tracking visited nodes during PyType graph cloning
This also avoids calling potentially expensive `hashCode`/`equals` for deeply nested types.

Space-RevId: 269d3e2d1ebf299c3eea45ddcc1955190577bc6f

GitOrigin-RevId: 35e195b49084e0cb0a071db83607117e98e38451
2026-01-22 21:52:47 +00:00
Petr
89de3dc87d PY-86223 Get rid of FRAGMENT_OWNER in PyTypingTypeProvider
Space-RevId: 094b32fd517958b8eb87186669269f7154315a89

GitOrigin-RevId: c68d872b5c9b1c2e8a700e66c3a08fe10f40050e
2026-01-22 17:32:16 +00:00
Petr
b0697d6b99 PY-86223 Fix context for type hint code fragments
Use the containing PSI element as the context for the type hint code fragment instead of the whole file. This allows resolving symbols within the local scopes.

When looking for a start instruction in `PyDefUseUtil.getLatestDefs()`, use the parent element's instruction if the element itself is missing from the CFG.

Fix resolution of string type hints and comments by allowing forward references in PyExpressionCodeFragment.

Space-RevId: b44603176d5b50b20f9a5964714d3661d71c8a08

GitOrigin-RevId: 715bcd011543c060e0dff965d94fbd8cc6f7e591
2026-01-22 17:32:16 +00:00
Petr
5228aa38cb PY-86223 Cleanup: Minor code deduplication in PyTypingTypeProvider
Space-RevId: 0ab7380b214a3355d92fa8a4930b0cad07ae5111

GitOrigin-RevId: bec27ecac63dc821ea3304ffee71c2a9fead787a
2026-01-22 17:32:16 +00:00
Petr
3d0c5e2a6d PY-86223 Cleanup: Move PyClassElementType.getSuperClassExpressions to PyTypingTypeProvider and make it private
Space-RevId: 4f3324b8488a678e2ac9f3d46f3b17ab55f3bf23

GitOrigin-RevId: 599a21987345ad962dc6d25e603e1b42da54fa7e
2026-01-22 17:32:16 +00:00
evgeny.bovykin
d7b180e15d PY-86219 Use weak keys for TypeEvalContext caches by default
Space-RevId: 5bd8593af2f394e5dffaf8d120aad81c1735ed22

GitOrigin-RevId: e61a25688688e216eeddfd0e2212a6a9796cf2f7
2026-01-22 15:36:41 +00:00
Andrey Vokin
ee714dc1b8 PY-83505 support classes from builtins
(cherry picked from commit 3d352a170fa5f9e6e487e3bc8a01ad61dbeeea1d)

IJ-CR-188791

Space-RevId: 86d47f7aaac11cf58f68494e8b20e8da629b190d

GitOrigin-RevId: 11206c73e8390f5a7296822c450cb3a285ce0b6d
2026-01-22 11:19:15 +00:00
Morgan Bartholomew
c717dfe5b2 PY-86754: type representation: support function types
Space-RevId: 0f8a8141714b5360f9ae4ac6b1b14cf12eb2a156

GitOrigin-RevId: 62466e57a8e09cf73c6a4f4171e77367c731a1fa
2026-01-22 10:42:28 +00:00
Andrey Vokin
e7ebf8cc67 PY-86891 support module type parsing
(cherry picked from commit 0ad4dee34fe8cb9679bc2e8ae64b7f215d3eb37e)

IJ-CR-188572

Space-RevId: 6fa5e775ae291ae631bbeab7a32fbb42d9aa9f58

GitOrigin-RevId: adf46e12834257c14237097a452399f832b0b106
2026-01-21 15:13:30 +00:00
Tagir Valeev
7ee60c5957 IJPL-230888 [mod-completion] Use BaseCompletionParameters where possible for sorting
GitOrigin-RevId: d523b1ab329ce0a5758aa661f16c796ff0e08396
2026-01-21 11:23:02 +00:00
Mikhail Golubev
339cbe574c PY-86655 Make async for require __aiter__, not __iter__ when constructing structural types
GitOrigin-RevId: 7554da6ad659681763b88d238640d9ab1185e495
2026-01-19 20:46:01 +00:00
Mikhail Golubev
9b9620f481 PY-86653 Consider conditional expressions and match statements when constructing structural types
similarly to how we already skip `if/elif/else` branches.

GitOrigin-RevId: 5afea67929bb79be97521349380100b005a175c7
2026-01-19 20:46:01 +00:00
Mikhail Golubev
38ec97a466 PY-85030 Remove previous incomplete check against parameter reassignments
Since we use flow-sensitive name resolution for attribute qualifiers,
it's sufficient to check that they don't resolve into definitions other
than the parameter being processed, no need to track reassignments
manually.

GitOrigin-RevId: ea321af075dc1c3a7b58f052b36eaf0ac832e37c
2026-01-19 20:46:01 +00:00
Mikhail Golubev
223a91c3ac PY-85030 When constructing a structural type, make sure attribute qualifiers refer to the original parameter on all paths
We already had protection against reassignment to a parameter name,
but it didn't take into account that we also skip conditional branches and loops
to collect only definitely accessed attributes of an object, so if reassignments
took place under conditions, even in every branch, they didn't prevent us
from collecting subsequently accessed attributes.

GitOrigin-RevId: d41b8f4c3dbce6643d915923172d32a8e4e6466c
2026-01-19 20:46:01 +00:00
Morgan Bartholomew
48378debba PY-82222: gtd: don't resolve a skeleton when there is a pyi
GitOrigin-RevId: dd0a8f526c9a55e6ccfd9aa163fab53ec2c07a6d
2026-01-19 10:27:14 +00:00