Commit Graph

6963 Commits

Author SHA1 Message Date
Morgan Bartholomew
b4d6ff2556 [python] PY-80252 disable PyUnnecessaryCast by default
because unsafe unions cause false positives

GitOrigin-RevId: 3fd8a018c60cc743d2e31c1d306612c94179d43c
2025-08-31 12:26:25 +00:00
Morgan Bartholomew
b9c06cd3b5 [python] PY-80252 set correct default highlighting for PyUnnecessaryCast
GitOrigin-RevId: fb0767353a298f95af63beee4f9c2db729d777ee
2025-08-31 12:26:25 +00:00
Morgan Bartholomew
467785be0e [python] PY-79178/PY-80252 report invalid and unrequired casts
Merge-request: IJ-MR-171620
Merged-by: Morgan Bartholomew <morgan.bartholomew@jetbrains.com>

(cherry picked from commit d9b13a99bad56a112f04febfc939823397b55ddd)

GitOrigin-RevId: a03b56b8c3ea58455af5100e59eab310776e063d
2025-08-31 12:26:25 +00:00
Petr
5de7e2eca5 PY-83741 Support type narrowing based on containment check for list and set literals
GitOrigin-RevId: 8c834433ef64c1906314d681383bdc258f4628bc
2025-08-28 16:40:57 +00:00
Morgan Bartholomew
6b50ea074f [python] PY-59986 fix type annotation injection for union operator
Merge-request: IJ-MR-171625
Merged-by: Morgan Bartholomew <morgan.bartholomew@jetbrains.com>

(cherry picked from commit 5bd3401e4a98fc615694dacb1d7fe7a1ddb68d3e)

IJ-MR-171625

GitOrigin-RevId: e18ed0b36044c659eae1d73fd29e5ec28425ad18
2025-08-26 02:15:17 +00:00
Aleksandr.Govenko
cc3889bf3b PY-82963 PyCharm doesn't infer correct type when matching multiple values
Initial implementation


(cherry picked from commit 79cd937a9e7b8157775f1b777b9377fb338c25ae)

IJ-MR-170885

GitOrigin-RevId: edfbf09c14724d2d69b2f3cbbcb05ce8c464fcf4
2025-08-20 13:33:28 +00:00
Aleksandr.Govenko
c043ee587d PY-79834 Pattern Matching: matching positional arguments for NamedTuples
(cherry picked from commit 3f570872c6034c0b23b52d81d8780ac398646b05)

IJ-MR-170061

GitOrigin-RevId: cb89aa5ac255c1a44d0eb08adc8600cc0f79e77c
2025-08-19 21:56:43 +00:00
evgeny.bovykin
6861b49e37 PY-79816 Introduce PyType#getMemberTypes and use it to infer __hash__ type of dataclasses
`getMemberTypes` should be used for members which have no PSI which can be used to resolve to. For example, `__init__` method in dataclasses are sometimes not present in the source code. Yet its parameters are always useful for the code analysis. In this case, `getMemberTypes` should be used.

(cherry picked from commit 2455ed05099842fc50e1fa2a196c4952b6444795)

IJ-CR-172940

GitOrigin-RevId: 1da7d966c9752b16afc6ec1c55e6606d8ff7b244
2025-08-19 19:06:44 +00:00
Aleksandr.Govenko
b27584c98b PY-83197 False positive This code is unreachable matching object field with other object fields
(cherry picked from commit b8a283f8227819d2777c0d0a561688e3f6a32c35)

IJ-MR-171819

GitOrigin-RevId: ec874b7af89305a139d8252abf3b81ce7d4e7a15
2025-08-19 17:47:25 +00:00
Aleksandr.Govenko
32153e86b0 PY-83237 False positive "This code is unreachable" after if check in a case
(cherry picked from commit 859b299589e217a827b7ea61d34e96e45eaf8dce)

IJ-MR-172390

GitOrigin-RevId: 60fa47fa0a13a040455ec4289e7be34fe2d48008
2025-08-19 16:11:36 +00:00
Mikhail Golubev
4aff3ed154 PY-83039 Don't trigger PyLiteralTypeCompletionContributor in cases like x = y.foo<caret>
It should be activated only for the simplest cases when the caret is either
inside an immediate string literal or its prefix is an unqualified reference
expression. It makes little sense trying to detect if something like
the literal string `"y.foobar"` is a possible value for `x`.

It's a relatively heavy completion contributor. It starts evaluating the type of
`x` flow-sensitively, analyzing all preceding function calls to take into
account `NoReturn`. It affects common workflows like typing out
`df = pd.` to create a new Pandas dataframe.


(cherry picked from commit f17fe2ce86ee100a3480a574c7f57a1bd67ec2d8)

IJ-CR-172165

GitOrigin-RevId: 4434488b1d2dae3ab7efd72e775b0c730268e51c
2025-08-18 11:48:31 +00:00
Aleksandr.Govenko
adcc559e5c PY-81676 Don't report lines with assert_never as unreachable
(cherry picked from commit afdbf35915823de02a6b8551f57770113d0feb2f)

IJ-CR-172556

GitOrigin-RevId: 0f8526e2877736ac606db9ed4657a530a66d6f23
2025-08-15 13:27:10 +00:00
Aleksandr.Govenko
21e8b573a7 PY-81861 Pattern matching for dataclasses - allow matching a subset of attributes
(cherry picked from commit 30a865e64cee7be630567b7d23223fc79eac9dbf)

IJ-MR-168826

GitOrigin-RevId: 8383913015485a6b6e477131c47d502bb655dd30
2025-08-14 20:56:06 +00:00
Andrey Vokin
b3a70daa05 PY-83118 Forward Reference Causes Import to Be Incorrectly Removed in PyCharm 2025.2
(cherry picked from commit fcf27e5c97e12498bc1c630f43e0a0876faba408)

IJ-CR-172300

GitOrigin-RevId: 7f3fcc83890a4ae0b0e7e6dd4ba363790f318eaa
2025-08-13 13:13:42 +00:00
Aleksandr.Govenko
4c890f2d47 PY-82707 Pycharm July 2025 EAP showing unreachable when using a subtype of Any
(cherry picked from commit c8a61ecc43754144679e5afc9f4623c02f558597)

IJ-MR-170092

GitOrigin-RevId: 612862aa2ce338a8f18e13197f483b936c9d0cdb
2025-08-11 09:57:17 +00:00
Ilia Zakoulov
a8675a61ac PY-82168: Implement inspection and quick fixes for dataframe and series in the conditions
(cherry picked from commit 658f2d5609852b00b7e1011c3841c7266c202686)

IJ-MR-168659

GitOrigin-RevId: 66806362570ef564b1495ba5a9afcd32a50859fb
2025-08-08 19:31:55 +00:00
Aleksandr.Govenko
6deddd7ee2 PY-81608 False positive "This code is unreachable" after try / finally if try has a while loop
(cherry picked from commit fbdefd71c5c9356c82d3c873426dd565dd95c613)

IJ-MR-169577

GitOrigin-RevId: b428a790336656088c9b3343a2f6772873cafca8
2025-08-08 18:19:44 +00:00
Aleksandr.Govenko
7e0924c394 PY-82712 False positive unreachable code after try / finally block if try has an if
(cherry picked from commit 53c13421523d780995fa83cc0625f6e99d5fe51f)

IJ-MR-169577

GitOrigin-RevId: f5254435a0512ba55db7fca9016a387740ac9b8b
2025-08-08 18:19:44 +00:00
Marcus Mews
2c3ae70ddd PY-83001 Extract method with type hints lacks return type sometimes
- fix missing return type when last statement is a return statement
- add/adjust tests
- add missing null annotations

GitOrigin-RevId: 8fed189d0130c3b41a5f17a3324684a29b39c0ef
2025-08-07 20:11:13 +00:00
Marcus Mews
4e83c0cd74 PY-22720 Extract Method does Not Preserve Existing Line Breaks
- keep empty lines between statements
- add test

(cherry picked from commit 276000bdce7ffee22ecd2e03d2ec4831dd8f6725)

IJ-MR-171066

GitOrigin-RevId: 15660649de5c799be2dee8c5c80e616827ef41db
2025-08-05 12:33:06 +00:00
Marcus Mews
3d25b26d0f PY-35287 Extract method with typehints
- customize extract method refactoring for Python using prefix Py
- option to enable/disable type annotations
- persist value of checkbox.isSelected
- run all extract method tests using types
- add specific typed test
- adjust api-dump.txt since some members of AbstractExtractMethodDialog were raised from private to protected
- small adjustment in test expectation of the inferred type

GitOrigin-RevId: be6e70dcb61c451debb98c10c0a001234188cb7d
2025-07-31 14:08:38 +00:00
Marcus Mews
0e231d8365 PY-79622: @typing.overload does not work correctly with decorator application syntax
- check all overloads of each decorator to retrieve type annotations

(cherry picked from commit 916e4f796e3295c413f93e3adebf64f4692c8c11)

IJ-MR-166976

GitOrigin-RevId: e11c82034e016c0ff21a4a95e71edf1c496b8116
2025-07-24 21:59:44 +00:00
Marcus Mews
1e1dc85113 PY-78413 No warning for awaiting a normal function if target in other module
- special case for awaiting a call to an imported, untyped, non-async function

(cherry picked from commit 8eec47ca4560ae0577e8c6157ef533952436b3b4)

IJ-MR-168288

GitOrigin-RevId: 5ae73b7b663e94996116706a775b9fed683f331e
2025-07-21 11:04:38 +00:00
Mikhail Golubev
c13b42f56c PY-82454 When a generic class is not parameterized in a type hint, parameterize it with defaults right away
Previously, we parameterized it in PyReferenceExpressionImpl#getTypeFromTarget
and PyFunctionImpl#analyzeCallType, but this substitution disregarded default types
and substituted free type parameters only with their bounds if those were present,
additionally diluting them with `Any` through a "weak type".

So if we had something like the following:

```
class Ref[T : str = str]:
    def get_self(self) -> Self: ...
    def get_type_param(self) -> T: ...

x: Ref = ...
x.get_self()  # Ref[str | Any]
x.get_type_param() # str | Any
```

it worked somewhat correctly only if the omitted type parameter had a bound
in addition to the default.

One notable example from the standard library is the `open()` builtin
returning `TextIOWrapper` that has a default type parameter `_WrappedBuffer`.
This type parameter ended up either substituted with a "weak type" `_WrappedBuffer | Any`
or completely erased.

This change allowed removing special-casing for Self in PyFunctionImpl#analyzeCallType.

GitOrigin-RevId: 6408d24186bf607a08006f15b380e1eb158e63eb
2025-07-18 17:46:54 +00:00
Daniil Kalinin
63d6f8b760 PY-75679 Do not narrow down the Self type in generic classes
GitOrigin-RevId: 278b0856811da34c431bdf5f438e719428a7aad2
2025-07-18 17:46:54 +00:00
Aleksandr Sorotskii
363175ed94 system python providers for unix/mac/win/legacy platform; pyenv/brew system python providers; PY-47379
(cherry picked from commit 02c3c3f3e682aa60e48bd429b7862d431ce5ddac)

GitOrigin-RevId: f0b84f7603bc2d3604d797f9d078a25c54e1ec3e
2025-07-18 12:52:47 +00:00
Aleksandr Sorotskii
dbcc824467 support for () in version spec; proper equals op
(cherry picked from commit b6dcc1204e225369df009a59ece08f5797138b0f)

GitOrigin-RevId: 74ca04448d7eac28d4454f70e88dd260a02fb3ec
2025-07-16 14:39:35 +00:00
Marcus Mews
7bfd231a33 marcus.mews/PY-55691
PY-55691: `Expected type 'Type[AttrsInstance]'` warning passing `attrs` class to `attrs.fields()`

- add member __attrs_attrs__ to classes decorated with attrs.define or similar

Merge-request: IJ-MR-165647
Merged-by: Marcus Mews <marcus.mews@jetbrains.com>

(cherry picked from commit 979f894e595d903c55f33c8bd4c5c3d06cb2fe6d)

IJ-MR-165647

GitOrigin-RevId: d668282db59d6a6fcea1d40bb36aa4ee48585dea
2025-07-15 06:09:10 +00:00
Morgan Bartholomew
e812c7d44b [python] PY-82265 edge cases for GTD
(cherry picked from commit 6de5053ef51534f6efe8a1ca4cf428b8d8c44cfa)

IJ-MR-166989

GitOrigin-RevId: 32b61d838cb740f75b4d16842a11bda770ec87fa
2025-07-10 16:22:13 +00:00
David Lysenko
b238e5f37a [pycharm] PY-79081 Add getVenvRootPath() tests
GitOrigin-RevId: 5eab8795fc18cd885ac9435004be58e5ff97712e
2025-07-09 13:53:14 +00:00
Aleksandr.Govenko
63a9e9092d PY-81482 assert True in try triggers "This code is unreachable" after finally
(cherry picked from commit 9e5ea2546169cda70f2aaf810fa2f27d13cb102a)

IJ-MR-167790

GitOrigin-RevId: 2f6158133cd075f4b7155e8fe922dcfa85155085
2025-07-03 17:58:56 +00:00
Aleksandr.Govenko
9575aedee8 PY-81936 Code unreachable under sys.version_info guards is not highlighted
(cherry picked from commit ea1c276b5648f0ca4237b770179b27d6c5ee1048)

IJ-MR-167790

GitOrigin-RevId: e76f0a1150903d9eb85141c6c4ac898f67584d3d
2025-07-03 17:58:56 +00:00
Aleksandr.Govenko
fefa1ad70a PY-81947 if x is not None check for a value of type Any | None makes the guarded code unreachable
(cherry picked from commit 4f374c34595414f20612062922b9e88c93f9ffc1)

IJ-MR-167790

GitOrigin-RevId: 74d6b3b61c6758beda87adebbe297c4da2cf6d1e
2025-07-03 17:58:56 +00:00
Aleksandr Sorotskii
7a65757b7d cleanup; unbundle vagrant plugin #PY-80258 Ready for Merge
(cherry picked from commit 43f8dda8114f1d78e43f54d11d43b072fd5e7bda)

GitOrigin-RevId: 16af4dc9778db240fb078cd8bdda77360b246c05
2025-07-03 17:51:14 +00:00
Egor Eliseev
dc428e32f4 PY-82241 Fix PythonDebuggerAggregatorEnvTest
Disable sys.monitoring from PyDB.stoptrace.
Disconnect DebuggerProcess if ServerSocket is closed.
Kill DebugProcessHandler if it is KillableProcessHandler.

Merge-request: IJ-MR-167442
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>
(cherry picked from commit f1a42ad9014d9e172bc994085f53e2123f9870c2)

GitOrigin-RevId: 7a7335ed4f83764e18390490999c06db9a35feb3
2025-07-02 07:22:22 +00:00
Ilia Zakoulov
a73bbf2a4d PY-71370: Resolve any suitable fixture candidate if pytest_plugins cannot be parsed
This bug was introduced during a refactoring of fixture support.
While the correct order of resolution was maintained, it relied on the assumption that pytest_plugins could be statically analyzed.

Consider the following example:
```python
import os
from glob import iglob

DIR_PATH = os.path.dirname(os.path.abspath(__file__))

def create_pytest_plugins():
    # Dynamically resolves fixture plugin names by scanning the fixtures directory
    fixture_names = _make_fixture_names("tests/utils/fixtures/**/*.py")
    return fixture_names

def _make_fixture_names(fixture_path_pattern: str):
    os.chdir(f"{DIR_PATH}/../../")
    return [
        _make_fixture_name(fixture_path)
        for fixture_path in iglob(fixture_path_pattern, recursive=True)
        if "__" not in fixture_path
    ]

def _make_fixture_name(fixture_path: str) -> str:
    return fixture_path.replace("/", ".").replace(".py", "")

pytest_plugins = create_pytest_plugins()
```
In such cases, where pytest_plugins is resolved dynamically and cannot be parsed statically, it is preferable to fall back to resolving any other suitable fixture found in the project, rather than skipping resolution altogether.


(cherry picked from commit 2d9a5dd6bd34d1c06d47b3587cd365696642ccd7)

IJ-MR-167570

GitOrigin-RevId: 709f080d6c23d1f76ad397cb6363e74623758cfd
2025-07-01 15:11:20 +00:00
Nikita.Ashihmin
5dcdfc85ce PY-19974 Packages: Fix that conda do not set associated module by default
Signed-off-by: Nikita.Ashihmin <nikita.ashihmin@jetbrains.com>


(cherry picked from commit c863f53ccba93e177c5092194c9c7aa608e2b932)

IJ-CR-167014

GitOrigin-RevId: 6144bec9a086b1639f2475e853f0e2034632cda5
2025-06-25 21:05:50 +00:00
Morgan Bartholomew
ba3ef61694 [python] PY-81789 filter unhelpful declarations for GTD
(cherry picked from commit 0fba00400382b32bbdbb1d6112126b4097895f2f)

IJ-MR-165350

GitOrigin-RevId: dd3ce79429be222443d8d2d17b490670f84800f9
2025-06-23 12:19:07 +00:00
Nikita Ashihmin
05e32e764d PY-19974 Packages: Add conda envinroment.yml support, refactor sync methods
Signed-off-by: Nikita.Ashihmin <nikita.ashihmin@jetbrains.com>


Merge-request: IJ-MR-164824
Merged-by: Nikita Ashihmin <Nikita.Ashihmin@jetbrains.com>

GitOrigin-RevId: 85cbf7b873742ded72029af1f4ff3e34af9bae22
2025-06-17 00:18:33 +00:00
Mikhail Golubev
4f52bfea7a PY-79488 Automatically exclude root-level ".venv" directories in uv projects
GitOrigin-RevId: 1aa3befee0151ed6dce480ecaa7aef1e32ed9a3c
2025-06-16 14:03:36 +00:00
Aleksandr.Govenko
b0ca1ef976 [python] PY-81674 Highlight all unreachable code gray
GitOrigin-RevId: 5a8dba3a51b7e9d415deb5401213ad3b79ddd3c5
2025-06-13 16:56:16 +00:00
Nikita Ashihmin
1480554414 PY-81864 PyPackages: Move saved requirements.txt path from module to sdk
Signed-off-by: Nikita.Ashihmin <nikita.ashihmin@jetbrains.com>


Merge-request: IJ-MR-165494
Merged-by: Nikita Ashihmin <Nikita.Ashihmin@jetbrains.com>

GitOrigin-RevId: fc852bf8db5ebda9a138c2b7cc2f096143adce7b
2025-06-13 15:38:02 +00:00
Mikhail Golubev
14d3f67525 PY-79488 Support PEP 621-style path dependencies in Poetry
GitOrigin-RevId: fd4dfce4af8ca5cad3f2fba25aaf573d4df74d1f
2025-06-11 16:54:32 +00:00
Mikhail Golubev
91e9250379 PY-79488 Recognize "src" directories inside Uv/Poetry projects as source roots
GitOrigin-RevId: 62c904fa781882c3ea5636309d7b35d9092ee5b0
2025-06-11 16:54:32 +00:00
Mikhail Golubev
dc35398ca0 PY-79488 Drop "Py" suffix from Uv and Poetry Open/Sync tests, add "Project" in their names
GitOrigin-RevId: 4709324d6489c33a8897f3561609a3fbe922ac2c
2025-06-11 16:54:32 +00:00
Mikhail Golubev
1a5ea1b01b PY-79488 Try automatically configuring SDK for all modules in a uv workspace
GitOrigin-RevId: 24b825b85f23ac7c6338585cfc87fbe374428779
2025-06-11 16:54:32 +00:00
Mikhail Golubev
0b6c5f164b PY-79488 Keep the information about Uv workspaces in the workspace model
Piggyback on ExternalSystemModuleOptionsEntity for the time being.

GitOrigin-RevId: 899a72018e8f72ed326078ccbc1315cb59cbe227
2025-06-11 16:54:32 +00:00
Mikhail Golubev
35c66600cc PY-79488 Expose more system-specific information in project graphs
In particular, for uv, retain the information about workspace membership.
Make discovery of nested workspace members more robust.

GitOrigin-RevId: 9af260bbb47baac9d5fec7e2b605931ceb0ce3c4
2025-06-11 16:54:32 +00:00
Vitaly Legchilkin
286e78fe3c [python] cleanup (PY-79881)
* get rid of deprecated v1 package, move everything target-related to the com.jetbrains.python.target.ui package

Merge-request: IJ-MR-165173
Merged-by: Vitaly Legchilkin <Vitaly.Legchilkin@jetbrains.com>

GitOrigin-RevId: efd869aa96f8a24fa6dc391b28068c9a0d175178
2025-06-11 09:27:38 +00:00
Ilya.Kazakevich
2e14347844 Python: extract python-specific extensions from exec service to simplify API and make it extendable for intepreters.
Use `ExecService` `api.kt` to exec any binary and extensions from `execService.python/api.kt` for python-specific things (i.e helpers)

GitOrigin-RevId: bb217798a9d1ee886c4b12220ec1f66a5ef08336
2025-06-07 22:05:56 +00:00