2668 Commits
Author SHA1 Message Date
Mikhail Golubevandintellij-monorepo-bot 481b968a7c PY-85997 Implement missing findMember and getAllMembers in PySelfType
Turned out, previously such recursive protocol declarations, when
one of its methods returns the same protocol and the corresponding
implementation method returns `typing.Self` where handled thanks
to considering PySelfType as unknown (see `PyTypeCheker.isUnknown()`),
so a raw, not substituted, `Self` matched any protocol.

We didn't get notable false negatives due to that because normally
PySelfType is substituted with the corresponding receiver type
before matching, and protocols are one of a few exceptions,
where we match against raw Self in method signatures.

Matching such a protocol with an implementation returning not
`typing.Self`, but the same class, always caused recursion guard hits.
Now that PySelfType is considered equivalent to its scope class type,
implementations using Self also trigger it. I've added explicit tests
on that for further investigation.

GitOrigin-RevId: 2cc0432438f0049db005ad50c563f20cc845e44e
2026-01-02 16:50:34 +00:00
Andrey Vokinandintellij-monorepo-bot 4bf819f89f Revert "[python] PY-86493 Pyrefly: Support type resolver"
This reverts commit 890c86d623905493063823b4bc03b6153069e0c1.

GitOrigin-RevId: aa943156ae095da9a9c87f8dfce960596981f183
2025-12-25 11:12:00 +00:00
Nikita Ashihminandintellij-monorepo-bot c220374f68 [python] PY-86493 Pyrefly: Support type resolver
Merge-request: IJ-MR-186102
Merged-by: Nikita Ashihmin <Nikita.Ashihmin@jetbrains.com>

Key features:
- Added Wrapper PSI elements that are not sent to Pyrefly for type calculation because they simply use the type of another element.
- Added more instant type annotations for types that do not require context for type calculation.
- Supported Pyrefly LSP type inference. To use it, the following fork is required: https://github.com/nashikhmin/pyrefly
- Added a separate context because built-in constraints are not applicable to Pyrefly.
- The first ten types are calculated one-by-one to ensure quick responses for completion; however, subsequent types are calculated in batches for better time efficiency.

GitOrigin-RevId: 890c86d623905493063823b4bc03b6153069e0c1
2025-12-23 19:00:25 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 764fbaf1ef PY-49165 PY-86123 PY-86124 Improve after review
GitOrigin-RevId: 581c80229ca4f9e3a1faab057d0a3c689e2ce96e
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot d9b6a0fa68 cleanup [python]: Convert isProtocol to extention function
GitOrigin-RevId: 9a6b4b14f52ab44644eedd2d122f2067d7593ad7
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 923c08b3f7 PY-86507 Check protocols in class patterns
GitOrigin-RevId: bb23c315d4ea7f022fedd0226260d9054252e418
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot e18284519a PY-86124 Mark positional patterns after keyword patterns as error, and suggest quickfix
GitOrigin-RevId: 82650b5e5de755a6d8130aae345c46d360546cb4
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot aa58078ab8 PY-79834 Fixed pattern matching logic for untyped namedtuples
GitOrigin-RevId: a376074a7869e8278d3c60a0389064616b536472
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot af0f19abb9 PY-86123 Add navigation to attribute for keyword pattern inlay hints
GitOrigin-RevId: aeabf8a75d4725be7a17a20be34a22ad45a31c15
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 1c34e08d66 PY-86123 Add inlay hints for positional patterns in a match/case statement
GitOrigin-RevId: bba519b0ed7b2529f719ae1aaaf23e893761c90e
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 152f63401c PY-49165 Add tests for PyPatternInspection and related quickfixes
GitOrigin-RevId: 0e35bd5d50e2d6b544cbd4467d184b6be21b7574
2025-12-22 22:36:14 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 6fd9133f29 PY-49165 Add references from __match_args__ to respective members
GitOrigin-RevId: 026a284e9cce777000958996aa70b5ff8826843b
2025-12-22 22:36:13 +00:00
Aleksandr.Govenkoandintellij-monorepo-bot 02990fbff8 PY-49165 Pattern Matching quick fix to add __match_args__
- Added PyPatternInspection class with logic to highlight and fix issues in pattern matching
- Modified PyAstAsPattern.getTarget() to return nullable value
- Added quick fix for PyAsPattern to simplify patterns
- Added quick fix for PyClass to add `__match_args__` attribute based on `__init__` signature
- Added PyRemoveElementFix quick fix to clean invalid list elements
- Added validation in PyPatternInspection to detect excessive positional patterns
- Added conflict detection between positional and named patterns in PyPatternInspection

GitOrigin-RevId: 64a1693aae2d243b83c46883a5d8476e727562a8
2025-12-22 22:36:13 +00:00
Mikhail Golubevandintellij-monorepo-bot 405dafb8fe PY-86463 Handle generic protocol inheritance during matching
When we have a protocol hierarchy, such as the following

```python
class P[T](Protocol):
    def method(self, x: T) -> T:
        pass

class P2[T](P[T], Protocol):
    pass

def expects_generic(x: P2[str]): ...
```

substitutions extracted from the expected type `P2[str]` of `x` are:
```
T@P2 -> str
T@P -> T@P2
```

Doing `expectedSubstitutions.withOnlySolvedSubstitutions(context)) then
throws away `T@P -> T@P2` mapping, so we lose that `T@P` is supposed to be str.
It means that during matching of `P.method` we match its unbound T@P
with any actual type, causing false positives.

On the other hand, if `expects_generic` was supposed to bind its own parameter,
e.g. as if in

```python
def expects_generic[T](x: P2[T]) -> T: ...
```

we cannot restore the actual type of `T@expects_generic` in the

```java
if (expected instanceof PyCollectionType) ...
```
branch at the end, because we try to match
`P2[T@expects_generic]` (expected type) with `P2[T@P2]` with substitution `T@P -> str`
(for example). Again, because the mapping `T@P -> T@P2` is lost, we end up
only binding `T@expects_generic -> T@P2`.

Now we substitute everything into the "raw" protocol member type before
matching it with the implementation, so we map `T@expects_generic` right away
when matching `P.method` with implementation,
and then we only need to insert this type into the expected
`P2[T@expects_generic]`.

GitOrigin-RevId: 88c91add1cca181db14f3276f944a84dffcd6517
2025-12-22 19:38:56 +00:00
evgeny.bovykinandintellij-monorepo-bot 453bfc627f PY-85123 Fix protocol substitution when matching it against a concrete class
GitOrigin-RevId: 46438cc4d035c75fb51217ba8eef927144d84a3b
2025-12-22 19:38:56 +00:00
Daniil Kalininandintellij-monorepo-bot 34eafbc5cf PY-86310 Code Insight: Fix false-positive "Type alias is not generic or already specialized"
Correctly resolve type aliases to their declarations

GitOrigin-RevId: 1bf29bf68e8c79dc3e403b7addf9e62ead8cd7d3
2025-12-22 18:27:31 +00:00
Andrey Vokinandintellij-monorepo-bot 6beceb495c PY-84034 ty type getting strategy
For testing purpose let's start with request per each typed element.

GitOrigin-RevId: f6bcf9c5584e01c2b22340eceb38a24b3be20a74
2025-12-19 19:05:37 +00:00
Marcus Mewsandintellij-monorepo-bot 56aa909fdb PY-84995 False-positive: Can't assign to dataclasses with slots=True
GitOrigin-RevId: c405f44b70c044c6c1855615523dc9869bf45be1
2025-12-19 18:22:37 +00:00
Nikita Paniukhinandintellij-monorepo-bot 33ed1d33ec [python] PY-82717 Upcast Literal type for parameters with default value
GitOrigin-RevId: 481d6d823ccae1621b160418c8a86a72831a3cce
2025-12-19 17:53:25 +00:00
Petrandintellij-monorepo-bot fe115b60d1 cleanup [python]: Remove unused code (PyDefUseUtil)
GitOrigin-RevId: 013997b72e6715bdb5d0a001000034a2229a647d
2025-12-18 19:07:52 +00:00
Piotr Tomiakandintellij-monorepo-bot 6bdf6bc2cd IJPL-222467 Python: optimize access to caches during stub building with StubBuildCachedValuesManager
GitOrigin-RevId: 37c5ae56d98b1ca234dd5a1707f6780fccceb50b
2025-12-16 18:11:33 +00:00
chbndrhnnsandintellij-monorepo-bot b9dab0fe25 [python] PY-86190: Enable missing interpreter warning on empty file.
PR: https://github.com/JetBrains/intellij-community/pull/3341

GitOrigin-RevId: 04c927e2c37a9a8c9ae0d5612efec4f1ea9b5b05
2025-12-15 19:04:20 +00:00
evgeny.bovykinandintellij-monorepo-bot ae31c8397d refactor pycharm: Remove mainElement property from PyTypeMember. element should be used instead
GitOrigin-RevId: e9dce24833d0770d44926d51b7eae03b8975ebe7
2025-12-14 21:38:04 +00:00
Petrandintellij-monorepo-bot eb116ceb78 PY-76859 Report a warning if annotation for the self parameter of __init__ method contains class type variables
GitOrigin-RevId: 5ad374adfedaf426b32ddbd6facd077a506c9248
2025-12-10 18:17:49 +00:00
Petrandintellij-monorepo-bot 765735660d PY-76859 Report a warning if a class being constructed does not match __init__ method's self parameter type
GitOrigin-RevId: ba64f70594968e4e2981e590d0f0c3d00003f7da
2025-12-10 18:17:49 +00:00
Petrandintellij-monorepo-bot 046cafe8b4 cleanup [python]: Inline method (PyCallExpressionHelper.kt)
GitOrigin-RevId: 2cfb2265b53c9b3fd0fa50606b67740dd83b35e5
2025-12-10 18:17:49 +00:00
Petrandintellij-monorepo-bot bffad2a72d cleanup [python]: Replace redundant logic with filterValues() call (PyCallExpressionHelper.kt)
GitOrigin-RevId: baadbadebacab3b0d184afee25332b2fee6c1706
2025-12-10 18:17:49 +00:00
Petrandintellij-monorepo-bot 7db01edb1a cleanup [python]: Remove static import for ContainerUtil.exists() (PyTypeCheckerInspection)
GitOrigin-RevId: 82116b39734750c720d2dd674763c77226ada77d
2025-12-10 18:17:49 +00:00
Tatiana Berandintellij-monorepo-bot 9431f9ddca PY-82412 support go to definition on loop constructs [python]
Merge-request: IJ-MR-181460
Merged-by: Tatiana Ber <tatiana.ber@jetbrains.com>

GitOrigin-RevId: 81affdaa7f2e8747557444eb732f0fe106e0d224
2025-12-10 17:07:10 +00:00
Artem Ivanovandintellij-monorepo-bot 2ba79a9f54 PY-84606 Add inspection for unhashable dict keys and set elements
GitOrigin-RevId: 46ee338cc984b4278bbec19fb47ed7185764e3fa
2025-12-09 22:14:08 +00:00
evgeny.bovykinandintellij-monorepo-bot 6a772de5d5 PY-85638 PY-85893 Use soft-key soft-value map for TypeEvalContext caches
This prevents the caches from blowing up in size when analyzing a lot of files in a row

The most obvious example is running `Analyze code` on the whole project. Previously, all PSI elements from all files would pollute the cache, potentially consuming multiple Gb of memory. See PyDjangoSourcesPerformanceTest as an example. It used to require 16 Gb of heap, and it would still sometimes fail with OOM. Now, it runs smoothly with 2Gb of heap

GitOrigin-RevId: f9854f8abdd7086414df8f610b0f2d611ca0d455
2025-12-09 17:41:26 +00:00
Mikhail Golubevandintellij-monorepo-bot 3a2557def3 PY-85988 When cls in cls()` refers to a dataclass, its synthesized return type is Self
Because the callable type for dataclass callees is provided, the special logic for PySelfType
in `PyCallExpressionHelper.getExplicitResolveResults` didn't apply to dataclasses, so
invoking their constructor as `cls()` in class methods returned a concrete class instance,
not Self. I changed `PyDataclassTypeProvider.getDataclassTypeForClass` to accept a PyType,
instead of a raw PyClass, so PyClassTypeImpl and PySelfType (which is a PyClassType)
should be processed uniformly.

GitOrigin-RevId: 3ef0be3bfaec16283b7b74914e3e2dbee7c683cd
2025-12-09 17:13:33 +00:00
Mikhail Golubevandintellij-monorepo-bot 6c379d1764 style [python]: Get rid of snake_case in PyCallExpressionHelper.kt
GitOrigin-RevId: bb67e1fe0e340dd067d1d52769910ec5830aa758
2025-12-09 11:32:03 +00:00
Mikhail Golubevandintellij-monorepo-bot 0e132bf005 PY-85941 Use UnsafeUnion of ancestor classes as the result of super()
Ideally, it should be an intersection of these types, but UnsafeUnion
at least allows avoiding false positives.

GitOrigin-RevId: 154849f814921f3a13534b72a1d10d309069a23e
2025-12-09 11:32:03 +00:00
Petrandintellij-monorepo-bot 50c192c9a1 PY-85420 Rename namedtuple fields whose names begin with an underscore
GitOrigin-RevId: 4a8eb73f6ee9f514a44f51e08bb8a6f60e27246a
2025-12-08 16:01:13 +00:00
Petrandintellij-monorepo-bot 93430c5dfc cleanup [python]: Fix code inspections (PyNamedTupleType.java)
GitOrigin-RevId: 18d71438ad94b63edbfe449a92843f05c2e3276a
2025-12-08 16:01:13 +00:00
Azim Akhmadjonovandintellij-monorepo-bot 2e3d1fb6bc PY-46932 add completion for "async def/for/with" constructs
Merge-request: IJ-MR-183838
Merged-by: Azimjon Akhmadjonov <azimjon.akhmadjonov@jetbrains.com>

GitOrigin-RevId: 49e89dd8faede246674cef69545c4c12f7128c3c
2025-12-08 10:13:52 +00:00
Marcus Mewsandintellij-monorepo-bot 14e295879d PY-85390 Introduce PyExpectedTypeJudgement that aggregates related code
- introduces PyExpectedTypeJudgement as a single entry to compute expected types
- changes a few clients to use PyExpectedTypeJudgement

GitOrigin-RevId: 27734b99b37a364b540f8af985908b282c50afd7
2025-12-08 09:55:20 +00:00
chbndrhnnsandintellij-monorepo-bot be0a2a737e [python] PY-72251 Missing test run gutter icon for nested test classes
Merge-request: IJ-MR-181131
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: bae956b8083159c8f28391d058306afef60bf349
2025-12-06 15:30:13 +00:00
evgeny.bovykinandintellij-monorepo-bot 3358fb505a PY-84859 Fix IndexOutOfBounds in PyCallableTypeImpl#dropSelf
GitOrigin-RevId: 06b4772a2586e5cac79a2dfc0ac03f9bd0fa3d95
2025-12-05 23:49:20 +00:00
evgeny.bovykinandintellij-monorepo-bot 133bfdf47a PY-84859 Implement type inference for decorated definitions without expression fragments
GitOrigin-RevId: 28acd74cbf66bf997ef4436006d4d0f870794d4a
2025-12-05 16:28:36 +00:00
Nikita Paniukhinandintellij-monorepo-bot 082324404d [python] PY-82654 Format descriptions of Python inspections
GitOrigin-RevId: fa706b67efd8d3caafc15fa101514dd7cf1721b1
2025-12-04 14:02:23 +00:00
Nikita Paniukhinandintellij-monorepo-bot 788e8300e4 [python] PY-85601 Add "invalid escape sequence" inspection
GitOrigin-RevId: d750f06efc5e42678073de084ecb2976acedd4b9
2025-12-02 21:55:58 +00:00
Petrandintellij-monorepo-bot 39cac66e40 PY-41061 Fix type inference for (async) iteration over objects with both __iter__ and __aiter__
GitOrigin-RevId: 0eb20894a1df40b62b45e7ef0166a7ce72cdc753
2025-12-02 19:53:12 +00:00
Petrandintellij-monorepo-bot 18dcb8c149 PY-41061 Inline method
GitOrigin-RevId: d085c1e1b25ae9c42ae3d6a8bc735b46c784cbdb
2025-12-02 19:53:12 +00:00
Mikhail Golubevandintellij-monorepo-bot f7aaea8de8 PY-85948 Fix generating type hints with typing.Self
GitOrigin-RevId: 8ac15452085ac5b87e39dd514aad526bf7246086
2025-12-02 17:14:04 +00:00
Morgan Bartholomewandintellij-monorepo-bot 154d12a070 [PY-6591] use PyCodeInsightSettings.PREFER_FROM_IMPORT when moving module reference
GitOrigin-RevId: b8313661e3989ff0c62e12556368fc3fb696b136
2025-12-02 07:00:12 +00:00
evgeny.bovykinandintellij-monorepo-bot b9d62df917 PY-85880 Properly handle right-hand side calls in PyUnresolvedReferencesVisitor for strict unions
GitOrigin-RevId: a2d03ad6c6f9fb78c78eef3a3ada5509dd7dc4aa
2025-12-01 20:36:57 +00:00
Petrandintellij-monorepo-bot 1e07fdb86a cleanup [python]: Minor code deduplication (PyVersionSpecificBase.kt)
GitOrigin-RevId: 42e8cc2865d1db7c02c6f9e3c7b5da0ebdef9e6d
2025-12-01 16:08:37 +00:00
Azim Akhmadjonovandintellij-monorepo-bot ad4b95427c PY-76911 Conformance Test Failure: dataclasses_transform_meta.py
GitOrigin-RevId: 3f1b1db0d1a379cd81046d822340cff9fe672719
2025-12-01 12:25:50 +00:00