Commit Graph

6607 Commits

Author SHA1 Message Date
Egor Eliseev
ab01b20a6b PY-72345 Pycharm 2024.1 Broken debug on Python 3.12.3
1. Fix the registration of the `PY_RETURN` signal. Stop unregistering the `PY_RETURN` signal for a `code: CodeType` after the first processing of `PY_RETURN`.
2. Fix the `LINE` callback during stepping and `SMART_STEP_INTO` commands.
3. Fix the `PY_RETURN` callback. Added handling for `SMART_STEP_INTO` and `STEP_RETURN` commands.
4. Fix the `_should_enable_line_events_for_code` function. Registration of the `PY_RETURN` and `LINE` signals for a `code: CodeType`.


Merge-request: IJ-MR-149452
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

(cherry picked from commit 8590efb7a1b2d8d6ca2393f18dcbca795e35d211)

IJ-MR-149452

GitOrigin-RevId: 4a157651e52072f3bdc186a61af7562e05a53da7
2024-12-03 16:41:46 +00:00
Aleksandr.Govenko
d5f9bf8de0 PY-55548 Use actual return type for "Specify return type using annotation"
For async functions, unwrap return type from Awaitable or Coroutine


Merge-request: IJ-MR-146295
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

(cherry picked from commit 9fe8d02a9d8bb584b9d6972ce999912bd93875e6)

IJ-MR-146295

GitOrigin-RevId: 9bad4877a069268a2d0181cac70b9a0d399cb5e6
2024-12-03 16:06:45 +00:00
Irina Fediaeva
92365f2246 PY-52574: Update tests after removing Epytext docstring format
(cherry picked from commit d4a90a8da56ca889cf380aa5bc72ac82b0716abc)

IJ-CR-148150

GitOrigin-RevId: 235a0e447d84c96e9963235615b07a1caf371e74
2024-11-28 01:35:54 +00:00
Ilya.Kazakevich
9f31575c35 PY-77483, PY-75549, FUS-5195: Misc project pycharm (squashed commits from master)
Lots of files are picked from the master

GitOrigin-RevId: 88dfc699cbfa2be9b11d1645c2c24221d16fbdc4
2024-11-26 17:47:29 +00:00
Mikhail Golubev
535af53f05 PY-77168 Allow flow-sensitive resolve from unmatched version checks to reachable outer blocks
Also, don't query LanguageLevel for each element of each instruction,
only once per scope traversal.

This doesn't fix the problem with unreachable definition *inside* blocks under
unmatched version checks, i.e.

if sys.version_info < (3, 8):
    Alias = int
    expr: Alias # unresolved

but it's a more difficult problem how to handle those consistently with the idea
of unreachable version checks under the *current* interpreter version, and hopefully
it occurs rarer than, say, unresolved top-level imports of common names from typing.

(cherry picked from commit 55fd4597c6d0860d290caba15fbf4d313e985a86)

IJ-CR-149696

GitOrigin-RevId: 357ada7e10618aef75c470e6cd878f7672109e83
2024-11-25 22:38:29 +00:00
Mikhail Golubev
3fdadc1b6b PY-40458 Use overridden method's return type for overrides only if both are async or synchronous
Because async generator methods in ABC and protocols are supposed to be declared as
plain "def" methods so as not to confuse type checkers with their AsyncIterable
return type annotations, it's better to disable such type-hint re-use if methods
async-ness don't match and not wrap anything in typing.Coroutine implicitly.

See also https://mypy.readthedocs.io/en/stable/more_types.html#asynchronous-iterators

(cherry picked from commit 6342f15a7786ec0d02ee1ab2b18fd40fd1ca1430)

IJ-CR-149694

GitOrigin-RevId: 3e19f190d9334e6c8648462ebb5b61abe931b0e6
2024-11-25 22:38:29 +00:00
Mikhail Golubev
fae8df34f4 PY-36416 Don't wrap return types of overridden async methods in Coroutine twice
(cherry picked from commit 48d01bedeb62d1a232704e58a3f39e3a7d543d2d)

IJ-CR-149694

GitOrigin-RevId: e431744a18f2b9d2976de7ee12888961e22f2298
2024-11-25 22:38:29 +00:00
Mikhail Golubev
2864833fca PY-76642 Add correct imports when generating type hints containing TypedDict
(cherry picked from commit 5c7761bea54741d68a7137788a46785db61f4247)

IJ-CR-149697

GitOrigin-RevId: 9eafefe6cef2bd599e6b84cf7d199f72c675b14f
2024-11-21 15:09:57 +00:00
Mikhail Golubev
1d8c4eebd6 PY-46546 For Python 3.9+, on "Add type hint for ..." don't import obsolete generic aliases from typing
(cherry picked from commit 7bc7d79e4ad464b67792e19f1be6262946917619)

IJ-CR-149697

GitOrigin-RevId: 5ebc4ec0cf4e5aacffd3f3cd1f62bc5617ae8cf6
2024-11-21 15:09:57 +00:00
Mikhail Golubev
99a6645e5d PY-36889 Type check assignments to class/instance attributes outside of class bodies
Previously, PyTypingTypeProvider.getReferenceType returned a type from a class attribute
type hint only for assignment to instance attribute located inside a class definition.

In other words, here we inferred the expected type from the annotation
and reported incompatible types in assignment:

```python
class C:
    attr: int

    def m(self):
        self.attr = "foo"
```
but in the following we didn't:

```python
class C:
    attr: int

inst = C()
inst.attr = "foo"
```

Now we try to resolve any qualified target expression to a class
or instance attribute and then infer the type from the corresponding
annotation.


(cherry picked from commit 086dbb678a8cd89cfe332bf801631568fb6c3a4d)

IJ-MR-147382

GitOrigin-RevId: 4e3f71baa598d4caf684d0aeab23d1a9a688b94d
2024-11-19 17:25:06 +00:00
Andrey Vokin
5b0a0b90ee PY-51687 Ctrl-Click on TypedDict usage jumps to builtins.py instead of the TypedDict declaration in the use code
(cherry picked from commit 72d68f8b3099563f77eae1bfd9ef28b8f479a7cf)

IJ-CR-148264

GitOrigin-RevId: 95c8e88ac6e3aef6a8364c2a841a1a8bce2f4d3d
2024-11-12 21:16:33 +00:00
Egor Eliseev
dbee69ed0b PY-59838 Refactor Poetry package management
Associate poetry files ("poetry.lock", "pyproject.toml") with the Python Packages toolwindow.
Separate UI error handling from package management logic.
Add tests to check the installation and removal of packages using poetry and "pyproject.toml" modification.

Merge-request: IJ-MR-146002
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

(cherry picked from commit 2ab0816f10c970f738d6d931dc123481030cad38)


Merge-request: IJ-MR-148435
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: be957c5343b73264c78134f156ad0e4034b912f9
2024-11-11 15:50:51 +00:00
Mikhail Golubev
da2936d4a4 PY-42137 Report incorrect arguments if no overload matches
Previously, we reported call arguments only if either all callee
candidates have unmatched arguments or all call candidates have
unmatched parameters. When there was a mix of the two, we reported
nothing.


(cherry picked from commit 97b42faf10de74ee7cd10f934d9eb94e1c8bbb34)

IJ-CR-146869

GitOrigin-RevId: 8babfe6a8ad0152f985655eff27df4df68936594
2024-11-06 11:22:48 +00:00
Daniil Kalinin
ea62ea04bc IJ-MR-146029 PY-76149 simplify the check for expected type from __set__ and assigned value
Reword the inspection text
Co-authored-by: Mikhail Golubev <mikhail.golubev@jetbrains.com>

(cherry picked from commit cab3cb1bbb1316462ee3fd37e735765b31b8d5e8)

GitOrigin-RevId: e3288e503d714a1f76bd1a2e6a0553770e1cbad5
2024-10-28 20:14:19 +00:00
Daniil Kalinin
0f40a088df IJ-MR-146029 PY-76149 code review changes and improvements
* Remove unnecessary descriptor type inference from `PyTargetExpressionImpl.getType`
* Refactor overload resolution for synthetic calls, minor refactorings in PyDescriptorTypeUtil
* Add additional test for __set__
* Do not substitute missing argument types with implicit `Any` in PySyntheticCallHelper
* Always take the first overload for `__set__` if more than one is present

(cherry picked from commit 9d1f9d37f3ea23ce6145f82fc8f62212f744e858)

GitOrigin-RevId: 372dc0e8ccc32095aecf3f611645adc06c2873e9
2024-10-28 20:14:19 +00:00
Daniil Kalinin
c653a43cab PY-76149 Support descriptor types as annotations for dataclass fields
(cherry picked from commit 78a127e1a0083ece810ad996124ad6ea65887da2)

GitOrigin-RevId: 0c33fe51f5f13116f773577056317c537cbc83ef
2024-10-28 20:14:19 +00:00
Daniil Kalinin
4ad6f08f45 PY-76399 Support __set__ descriptor
Add API for inferring the expected type of `__set__` from `value` parameter
Add corresponding logic to PyTypeCheckerInspection to check if assigned value matches the expected descriptor type
Add tests on it

(cherry picked from commit b14ab7b2e40e225b508875a778ceae8986cbb291)

GitOrigin-RevId: 2b15b2b4527a95e5912897ba256dcc73d71c3dcd
2024-10-28 20:14:19 +00:00
Ilia Zakoulov
ab53444089 PY-76629: Get rid of Django skeleton tests
GitOrigin-RevId: e96b82a3bcba484a5321c54cd15ff755dd7e276d
2024-10-28 14:57:57 +00:00
Ilia Zakoulov
91f27d8587 PY-76629: Suppress PyProtectedMemberInspection if a member is defined in .pyi
Protected member should not be highlighted as a warning if it resolves to .pyi file.
We assume that everything in .pyi file is a public API.

GitOrigin-RevId: c8275f3e48e3cd69b1676de9b78606f28ea224c8
2024-10-28 14:57:57 +00:00
Daniil Kalinin
814b2947d3 PY-76680 Fix IOOBE: SmartList.checkOutOfBounds in PySyntheticCallHelper.java
(cherry picked from commit 737513a3a2b0c9564055ff17845cebb80af10cd2)

IJ-CR-147142

GitOrigin-RevId: 93bfc9464bcbc97ec80cb6ad4ed10c484f2ee9ec
2024-10-23 16:12:41 +00:00
Tagir Valeev
ac6e041167 Remove groovy-stdlib dependency where unused
GitOrigin-RevId: ecbe272c09c97517177b2214479f2644c1ef3229
2024-10-08 09:28:42 +00:00
Alexey Kudravtsev
fa88174b0a allow python quick fix tests to change document during highlighting
GitOrigin-RevId: f69e2b152a473941411e1574c79235c50e5e8922
2024-10-04 12:14:40 +00:00
Vladimir Krivosheev
2af05dec25 extract intellij.platform.ide.internal
GitOrigin-RevId: 0e5e80fd53c3ef15ed9835a9400381d383526ca3
2024-10-03 19:22:03 +00:00
Daniil Kalinin
783bbde096 PY-75760 - allow reference to another ParamSpec be default of ParamSpec type, simplify logic of generic substitution for TypeVars
GitOrigin-RevId: 9ca5d7f3529513c683424d2f4d6da75f40d58e4a
2024-10-03 12:19:06 +00:00
Daniil Kalinin
d29d55476e PY-75760 - adjust testTypeVarParameterizedConstraints test
Sacrifice this old test for a good cause. The inferred type of `my_list_t1` is now `List[null]` which matches with pyright - it also has no complaints in the changed fragment

GitOrigin-RevId: 2176ffa69c6a24ec55344f4294e04542185ca7e7
2024-10-03 12:19:06 +00:00
Daniil Kalinin
411f2af7ba PY-75760 Refactor the implementation of PEP 696 support - Tests
Change the expected type of `testNewStyleTypeAliasOneWithoutDefault` test (now it is the same as in pyright)
Add the same tests but using old-style type aliases

Add a couple more tests on aliased types for some tricky cases

GitOrigin-RevId: 9d289d8e0964c592f4282f9970eeb9a08a8105e5
2024-10-03 12:19:06 +00:00
Vladimir Krivosheev
26c94d85b0 extract intellij.platform.ide.remote
GitOrigin-RevId: 9d68fda3031f89d5b0207782e796a54f24683176
2024-10-03 09:58:11 +00:00
Mikhail Golubev
190a55438e [python] Special-case typing.Generic while calculating a class MRO
typing.Generic is a magical class that can be specified in any position
in the list of base classes, not affecting the MRO consistency. It's done by
the custom __mro_entries__ implementation in typing._BaseGenericAlias (Python < 3.12),
which skips this Generic entry if there are other generic classes following
it on the list of superclasses. Namely, it's possible to do the following:

```
class Base(Generic[T]):
    pass

class MyClass(Generic[T], Base[T]):
    pass
```

which would cause a TypeError for regular classes. Since it broke our implementation
of the C3 algorithm in PyClassImpl.getMROAncestorTypes, we now special-case it by
always moving typing.Generic to the very end of the base class list while constructing
MRO.

See https://github.com/python/cpython/blob/3.11/Lib/typing.py#L1298 for a pure-Python
version of typing._BaseGenericAlias.__mro_entries__ and a relevant discussion in
https://github.com/python/cpython/issues/106102.

GitOrigin-RevId: e7d765193d532ab8457133e8fb5ad06840d89225
2024-10-02 14:29:04 +00:00
Mikhail Golubev
5622587ae3 PY-76243 Add an extra test for an explicitly parameterized conditionally defined type alias
GitOrigin-RevId: c15c9d4d8edd36f5acc8ada8935c79e787b4bc3e
2024-10-02 14:29:04 +00:00
Daniil Kalinin
b934cfe38a PY-74231 Fix false positive "Statement expected, found Py:DEDENT" for a nested type alias
GitOrigin-RevId: 03d64abe2c949a5912eb5c16ef48a5149568d66f
2024-10-01 11:43:14 +00:00
Mikhail Golubev
e2d7d259e9 PY-76243 Don't build implicit union types for conditional definitions and names imported from stub packages
Also fixes PY-59014, PY-39761.

PyResolveImportUtil returns both .pyi stubs and the corresponding .py files for stub packages
to support partial stub packages. See the line:

```
groupedResults.topResultIs(Priority.STUB_PACKAGE) -> firstResultWithFallback(groupedResults, Priority.STUB_PACKAGE)
```

in PyResolveImportUtil.filterTopPriorityResults.

It means that, for instance, resolving the QuerySet name in type hints led to QuerySet
definitions from both places. Then, PyTypingTypeProvider.getType() for the reference expression
"QuerySet" returned a union type containing PyClassTypes for both of them, we couldn't parameterize
it in PyTypingTypeProvider.getParameterizedType and returned Any.

It's wrong that while evaluating type hints, we interpret multiple declarations as
a union type. Those should only be explicitly expressed with typing.Union or "|" operator.
This behavior was originally added in PY-18427 as an ad-hoc way to support version checks
for type hints, but now it seems detrimental because it's unclear how to parameterize
such implicit unions of generic types then.

Other type checkers also don't treat conditional definitions like that. For instance, for
conditional type aliases, Mypy complains about the name being defined twice and then uses
only the first definition, and Pyright doesn't consider names under conditions other than
version checks as valid type aliases at all. Both type checkers also support partial stub
packages properly.

GitOrigin-RevId: 1ecc7ab5d09625d10850ddc0e1f7761332ccddd5
2024-09-30 13:32:14 +00:00
Andrey Lisin
86a44e2b79 PY-72239 Cleanup: replace deprecated ImmutableSet.of with Collections.singleton
GitOrigin-RevId: 4d223701e964f19107d23ebcfeec8b86ab83210b
2024-09-30 11:02:49 +00:00
Andrey Lisin
aae7c6e856 PY-72239 Fix Python data viewer env-tests
GitOrigin-RevId: 19d66d158a367e98b1eead93955fcdea11f35e0d
2024-09-30 11:02:49 +00:00
Andrey Lisin
4843e1d6e4 PY-73432 Introduce checkbox option for enabling debugger server mode
GitOrigin-RevId: 7a9bc66ab59b2a209c15d3313256f2ebf61e2193
2024-09-26 13:47:19 +00:00
Egor Eliseev
ed136fcdd4 [python] Fix Python Console tests
Delete IPythonConsoleTest#testParsing: duplicates PythonConsoleParsingTest#testQuestionEnd. Fails because a virtual file is not marked as IPython.
PythonConsoleTest#testCompletionDoNotEvaluateProperty: rewrite to static.
DebugConsoleTest: delete deprecated python function.


Merge-request: IJ-MR-145576
Merged-by: Egor Eliseev <Egor.Eliseev@jetbrains.com>

GitOrigin-RevId: 3708defece0a957708073b524995c21e7d095224
2024-09-26 13:05:09 +00:00
Andrey Lisin
27c038505c IJ-CR-143143 Extract default port number right from registry
GitOrigin-RevId: 57024f04473d7685fc7644d33f2bd12551ae1364
2024-09-25 09:10:59 +00:00
Mikhail Golubev
cb838b6577 PY-60968 Add a more precise test emulating the scenario with Typeshed before its update
GitOrigin-RevId: d0422405cd2a37ee3ed8bed144b6e4c1e3267fe5
2024-09-24 12:19:35 +00:00
Mikhail Golubev
ffceeb161b PY-76076 Acknowledge sys.version_info guards in flow-sensitive same-scope resolve
sys.version_info guards are processed at the level of ScopeImpl.collectDeclarations and
PyResolveUtil.scopeCrawlUp in PyReferenceImpl.resolveInner, as implemented in
3318ff79cdcc5ba0ce5e4feb65abad5ad0f4acfa.
However, once we collected all name definition candidates flow-insensitively this way, in
PyReferenceImpl.getResultsFromProcessor, if the reference and these candidates were located
in the same scope, we completely ignored these variants and gathered reachable definitions all
over again from CFG using PyDefUseUtil.getLatestDefs. And the latter didn't consider version
guards at all. I've added version guard checks directly in PyDefUseUtil.getLatestDefs.

GitOrigin-RevId: 9f92eecd1eb1812bfbd2bf54f8192f45f0cf0a1d
2024-09-24 12:19:35 +00:00
Mikhail Golubev
de0f128ac5 PY-60968 Add a regression test, the problem itself was fixed by supporting sys.version_info checks (PY-34617)
Namely, acknowledging them for import statements in df52f60574962e1bc222121aadc082683de0a869.

Additionally, the problematic conditional import of dict in csv.pyi as

```
if sys.version_info >= (3, 8):
    from builtins import dict as _DictReadMapping
else:
    from collections import OrderedDict as _DictReadMapping
```

was removed with the recent Typeshed update in 94973415b96b2a0f859d29b0201d1ccee0d06462 (PY-73263).

GitOrigin-RevId: 1100fd0dd01be9200149a1216b207bffa7ab13d6
2024-09-24 12:19:35 +00:00
Ilya.Kazakevich
3689a45984 Python NPW and Add SDK refactoring:
In SDK:
* `v1`: legacy API that should be dropped (but still used by Python Plugin and DS)
* `v2`: slightly better API used both for new project and interpreter settings. Supports DSL UI validation. Must be adopted by DS and Python Plugin somehow.

In NPW:
* `newProject`, `newProject/steps` (aka `v1`) deprecated, used only by DS and Python Plugin.
* `newProjectWizard` (aka PyV3): the right new API to use. Sooner or later will be adopted by DS and Python Plugin

GitOrigin-RevId: c3d49ce95079dc5ba589955381ddfe42326295fd
2024-09-23 21:14:22 +00:00
Aleksandr Sorotskii
d67337d2c9 fix additional data creation for remote interpreters; (#PY-76055) Fixed
GitOrigin-RevId: 064cbbaeb5f4241b718c9e51df0396b49971a365
2024-09-23 16:37:06 +00:00
Ilya.Kazakevich
08b404640a Python tests: allowRootAccess to the python SDK.
GitOrigin-RevId: 2c5469b7b35d7a1276ab648b373db15284cb6623
2024-09-23 15:41:26 +00:00
Ilya.Kazakevich
2c510f644c Revert "Python: Allow access python roots in tests."
`Application` isn't always available at that time. It is better to register allowed roots directly in the tests.

This reverts commit 8f8bf13f859e9cf69ab424b8692968a18aa537cc.

GitOrigin-RevId: c5cf6ba7fb77a7bc350b090a450519ecff1472ad
2024-09-23 15:41:26 +00:00
Ilya.Kazakevich
0def6fd000 Python: Allow access python roots in tests.
On TC you are only allowed to access certain directories (temp dir, project roots and so on).

Some services might also access Python interpreter folders (to index python libs for example), hence we allow this too to prevent exceptions

GitOrigin-RevId: 8f8bf13f859e9cf69ab424b8692968a18aa537cc
2024-09-19 20:44:15 +00:00
Tagir Valeev
d013c9980e Remove redundant keySet/values calls
GitOrigin-RevId: e972012a4ead404120b0f947c79d059f6d96f942
2024-09-18 20:27:35 +00:00
Andrey Lisin
88e7feabc8 PY-73432 Add sleep call in test script to mitigate potential GIL blocking by single thread
GitOrigin-RevId: 10f93a092d6004cbba284e2152ce9064991f7d1b
2024-09-17 16:06:33 +00:00
Andrey Lisin
663b5dad42 PY-73432 Use Targets API in Python debugger test task; use debugger server mode in tests by default
GitOrigin-RevId: 050a261e6d8ded837ba6b33ec8da0d182468eedf
2024-09-16 18:27:23 +00:00
Vladimir Koshelev
77f726391c [pycharm] fix NPE if the generic type of narrowed type is unresolved or any PY-75961
GitOrigin-RevId: 1d186023446c81a9cd56269f25354d26e6c00d3a
2024-09-16 17:32:59 +00:00
Tagir Valeev
0262382d71 ModuleBuilder.getModuleType inheritors: raw type removed
GitOrigin-RevId: 454b9c1543c29e27cdb1c1656d9be82afd4d769e
2024-09-16 11:23:15 +00:00
Daniil Kalinin
0577faa530 PY-71002, PY-75875 refactor PEP-696 support, fix the issue when generic classes were wrongly parameterized when Any was used as an explicit type
The refactoring also fixes the problem with wrong types inferred for contextlib.contextmanager

GitOrigin-RevId: 1601047786a0c43a463a82225b18635d407bcb40
2024-09-13 08:45:13 +00:00