Commit Graph

6558 Commits

Author SHA1 Message Date
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
Aleksandr Sorotskii
c900467d05 PY-75682 prefer project local .venv directory instead of global one
GitOrigin-RevId: a5156a410b9ef959287af15f94eb7e95739afec5
2024-09-12 13:36:37 +00:00
Ilya.Kazakevich
6a9aebe3e6 Python: introduce failure as a sugar over Result.failure(Throwable(userVisibleText))
GitOrigin-RevId: cefb5234d830f4e306e385161dd07d35eb12989b
2024-09-11 23:49:58 +00:00
Mikhail Golubev
740771109f PY-54560 Fix handling of class-based field specifiers, add extra tests
GitOrigin-RevId: e411c00a4aeb12da59787c0273e678cab70b3e07
2024-09-09 23:17:25 +00:00
Andrey Vokin
e44c48a1b0 PY-73263 Python 3.13 Support - Code Insight - Typeshed
Temporary comment broken test

GitOrigin-RevId: 2563f368009933c2c51cb54bd865a22b5dcecf0d
2024-09-09 13:54:00 +00:00
Andrey Vokin
1041f5e6a0 PY-73263 Python 3.13 Support - Code Insight - Typeshed
GitOrigin-RevId: 94973415b96b2a0f859d29b0201d1ccee0d06462
2024-09-09 13:54:00 +00:00
Andrey Vokin
9293cc2ad7 PY-73263 Python 3.13 Support - Code Insight - Typeshed
update dataclass typeshed

GitOrigin-RevId: bda7fda7ef235351f9ec6b21aa9021d6dcbd8b80
2024-09-09 13:54:00 +00:00
Mikhail Golubev
aef3b8de3c PY-59198 PY-54560 Support "alias" parameter of attr and dataclass_transform fields
GitOrigin-RevId: 6a81d2a45d808391413b5c0b52c79f7f6c51dcbb
2024-09-09 11:34:15 +00:00
Mikhail Golubev
1da22d34fd PY-54560 Support PEP-681 dataclass_transform
`dataclass_transform` support posed a number of challenges to the current
AST/PSI stubs separation in our architecture. For the standard "dataclasses"
module and the "attrs" package API, we could rely on well-known names
and defaults to recognize and preserve the information about decorator
arguments and field specifier arguments in PSI stubs. With `dataclass_transform`
however, effectively any decorator call or extending any base class can indicate
using a "magical" API that should generate dataclass-like entities.
At the moment of building PSI stubs we can't be sure, because we can't leave
the boundaries of the current file to resolve these names and determine if these
decorators and base classes are decorated themselves with `dataclass_transform`.

To support that, we instead rely on well-known keyword argument names documented
in the spec, e.g. "kw_only" or "frozen". In other words, whenever we encounter
any decorator call or a superclass list with such keyword arguments, we generate
a `PyDataclassStub` stub for the corresponding class.

The same thing is happening with class attribute initializers, i.e. whenever
we see a function call with argument such as "default" or "kw_only" in their
RHS, we generate a `PyDataclassFieldStub` for the corresponding target expression.
Both of these stub interfaces now can contain null values for the corresponding
properties if they were not specified directly in the class definition.

Finally, for the `dataclass_transform` decorator itself, a new custom decorator stub
was introduced -- `PyDataclassTransformDecoratorStub`, it preserves its keyword
arguments, such as "keyword_only_default" or "frozen_default" controlling
the default properties of generated dataclasses.

Later, when we need concluded information about specific dataclass properties,
e.g. in `PyDataclassTypeProvider` to generate a constructor signature, or in
`PyDataclassInspection`, we try to "resolve" this incomplete information from stubs
into finalized `PyDataclassParameters` and `PyDataclassFieldParameters` that
contain non-null versions of the same fields. The main entry points for that
are `resolveDataclassParameters` and `resolveDataclassFieldParameters`.
These methods additionally handle the situations where decorators, superclass
lists and field specifiers lack any keyword arguments, and thus, there were no
automatically created custom stubs for them.

All the existing usages of `PyDataclassStub` and `PyDataclassFieldStub`
were updated to operate on `PyDataclassParameters` and `PyDataclassFieldParameters`
instead.

Counterparts of the tests on various inspection checks for the standard dataclasses
definitions were added for dataclasses created with `dataclass_transform`, even
though the spec is unclear on some aspects the expected type checker semantics, e.g.
if combining "eq=False" and "order=True" or specifying both "default" and
"default_factory" for a field should be reported.
I tried to follow common sense when enabling existing checks for such arbitrary
user-defined dataclass APIs.

GitOrigin-RevId: 4180a1e32b5e4025fc4e3ed49bb8d67af0d60e66
2024-09-09 11:34:15 +00:00
Mikhail Golubev
a20dc6e783 PY-54560 Rename some DataclassInspection tests specific to attrs
GitOrigin-RevId: 14a65a75454507867df5212dd25425178975860d
2024-09-09 11:34:15 +00:00
Daniil Kalinin
82fca2f070 PY-71002 PEP-696: Add an inspection that checks that non-default Type Parameters in declarations cannot follow the default ones
GitOrigin-RevId: 29c63024a67802457e031821e33925287f21a2ab
2024-09-07 11:11:13 +00:00
Daniil Kalinin
6279c7a3c0 PY-71002 PEP-696: Add a set of tests that covers PEP's functionality
GitOrigin-RevId: 5d14970b62451233e8852df77a6938a18b3a17b9
2024-09-07 11:11:13 +00:00
Daniil Kalinin
7751fceaed PY-71002 PEP-696: Support new syntax for default types of Type Parameters in new-style declarations
- PEP-696 adds a new syntax for declaring the default types of Type Parameters in new-new style generic classes, functions and type alias statements. Support these grammar changes.
- Store info about default types in stubs for Type Parameters
- Increment the stub version counter in PyFileElementType

GitOrigin-RevId: b6b22e3eaa86ce06132885781e5775a89bf4b840
2024-09-07 11:11:12 +00:00
Petr
4221e99ae6 PY-72951 Integrate PyCharm with the conformance test suite
GitOrigin-RevId: 1b45a7a94248b06e6610f42af01bb84be9a40bb3
2024-09-05 12:55:28 +00:00
Petr
753596ee0a PY-34617 Take into account sys.version_info checks when analyzing Python files
Slightly improved PyStubsTest's readability

GitOrigin-RevId: e7c52cfafa206ed4839052e1040327ebbd3bc46b
2024-09-05 11:17:16 +00:00
Petr
db52d4ec3d PY-34617 Take into account sys.version_info checks when analyzing Python files
Support version checks for import statements.

GitOrigin-RevId: df52f60574962e1bc222121aadc082683de0a869
2024-09-05 11:17:15 +00:00
Petr
79dc479c63 PY-34617 Take into account sys.version_info checks when analyzing Python files
Support and, or, <=, > operators in version checks.

GitOrigin-RevId: 5006e88b0f7935d0bf0841dfd5fad5c371e8ff12
2024-09-05 11:17:15 +00:00
Max Medvedev
3f27a3edf1 cleanup: introduce LanguageRefactoringSupport#getInstance
GitOrigin-RevId: 832c2688ee1976e8e353291c645b676c77ecd2ce
2024-09-04 19:37:00 +00:00
Andrey Vokin
32ea6b0959 PY-75654 False positive "Cannot overwrite TypedDict field" overriding ReadOnly field
It's possible to override TypedDict attributes if their type can be matched.

GitOrigin-RevId: 1a7830a9dab043982456ab1555cb3d3aaad2e011
2024-09-04 13:47:22 +00:00
Andrey Vokin
08ad3f7789 PY-75655 False negative when updating ReadOnly TypedDict field using update() method
GitOrigin-RevId: 42428a0541893481046952407fce2d99a02081fa
2024-09-04 13:47:22 +00:00
Daniil Kalinin
681e3a7d58 PY-71748 change default receiver for __eq__ and __ne__ operations (== / !=) from right to left
GitOrigin-RevId: ef77e470061fd71bd8f12c51353fa84968c28856
2024-09-04 10:57:28 +00:00
Daniil Kalinin
c71a02fa78 PY-26184 fix type hinting information for bound generics lost in descriptors
As far as `__get__` call when accessing the attribute is implicit, create a synthetic call considering the type of callsite (access via instance or via class) and use its type as a type of property typed with descriptor class.

GitOrigin-RevId: acc36ebd2d62acfe99a5202b2478356f7b7aea46
2024-09-04 10:57:28 +00:00
Daniil Kalinin
ea989a3e05 [python] Create an API which allows inferring result types of "synthetic" function calls
In other words, this API allows inferring results of function calls based only on the type of reciever (e.g., class), if exists, and types of arguments passed to the function. The aim of this API is to replace the existing approach where we infer types of such "synthetic" calls by creating a new expression using `com.jetbrains.python.psi.PyUtil.createExpressionFromFragment` and then inferring the type of created expression

GitOrigin-RevId: 09bee7ba1757cb07910be245253fe4bd855f5076
2024-09-04 10:57:28 +00:00
Andrey Lisin
c5695b1efe PY-73432 Delete RecurrentTaskExecutor class and its tests due to deprecation
GitOrigin-RevId: 86dbdbefbb784a0f2d54ede8a5c244a19e944ac0
2024-08-29 12:13:31 +00:00
Petr
5d2d6cc722 PY-23067 Pycharm not picking function metadata from functools.wraps with methods
GitOrigin-RevId: d95c1a8f64a6e58d1a6c6c65866b6ab08aaf71b3
2024-08-28 20:02:44 +00:00
Aleksandr Sorotskii
eaf543252e remove dead code
(cherry picked from commit 7a97419cf82a50a6bbd913d59a0ba8e0982c40b3)

IJ-MR-143310

GitOrigin-RevId: 8f5660470e739ae8d6c3bb2a91554db2ed9341a5
2024-08-26 14:46:33 +00:00
Mikhail Golubev
0ae7ade582 PY-34626 Make test names a bit clearer
GitOrigin-RevId: 0311ba9c7085725a918472946312dde164f8541c
2024-08-26 10:38:00 +00:00
Mikhail Golubev
f8d1dd1f85 PY-34626 Add the issue ID to tests, remove irrelevant statements in test data
GitOrigin-RevId: 0d8a82f2cb65534c4cb666f8254c1945fb004060
2024-08-26 10:38:00 +00:00
somethingnew179
467ea6dd47 PY-34626 Fix isMethodContext to exclude inner functions as methods
closes https://github.com/JetBrains/intellij-community/pull/2811

GitOrigin-RevId: 9268c21cf03158738ca059f8b19c803cb9c368f3
2024-08-26 10:38:00 +00:00
somethingnew179
2bf033e420 PY-49174 make Match and Case expressions folding
GitOrigin-RevId: c9b1b37a762ec0879eb2b7653ae14b34ae97dfc0
2024-08-26 10:38:00 +00:00
Nikita.Ashihmin
c3d76fcc00 PY-72994 Packages(refactor): Add install with option
GitOrigin-RevId: 64e7823def799c144be06213fe26198f74537775
2024-08-24 13:43:56 +00:00
Aleksandr Sorotskii
1cb0659dad python interpreter should be at least executable but not necessarily called python; PY-60259; PY-11992
(cherry picked from commit a9dd773947b75e850c1e74e209bec9330ae8d74f)

IJ-MR-143222

GitOrigin-RevId: 16f075b18210dbd73a8e04e86282064048c06b99
2024-08-24 00:37:05 +00:00
Vladimir Koshelev
b3b4bbc51d [pycharm] add TypeGuard/TypeIs related tests to PyTypeCheckerInspectionTest PY-74277
GitOrigin-RevId: 98353067c3eb38be3be29d6322ffb356df8822f5
2024-08-23 17:26:21 +00:00
Vladimir Koshelev
6c7c41abb8 [pycharm] add type hint checks about TypeGuard and TypeIs PY-74271
GitOrigin-RevId: 50835cffbddcb73ca0ec0aca2234a89f62d4b5fb
2024-08-23 17:26:21 +00:00
Vladimir Koshelev
8f1f5d99a4 [pycharm] create PyNarrowedType explicitly for TypeGuard and TypeIs PY-74277
GitOrigin-RevId: fe01878d76473c3c149ca520bf7978be49bfd097
2024-08-23 17:26:21 +00:00
Vladimir Koshelev
7cf7de79f5 [pycharm] PyUnboundLocalVariableInspectionTest: cleanup
GitOrigin-RevId: a41931087f8b48972b23e3aaf4b6cc3469175836
2024-08-23 17:26:21 +00:00
Andrey Lisin
834455dee9 Minor: rewrite PythonDebuggerPydevTest docstring for clarity
GitOrigin-RevId: d933971c67868bb87518f9a17f79c71bfbc66175
2024-08-23 16:27:37 +00:00
Andrey Lisin
84a016fd62 PY-73432 Run Python debugger in server mode by default
GitOrigin-RevId: 3cdce22120868761d823402bd6bcf660224591b8
2024-08-23 12:18:41 +00:00
Aleksandr Sorotskii
81e490cd6f cleanup sdk validation api
GitOrigin-RevId: 33747cf0cfada370181b43d02f203b8401740c5c
2024-08-22 19:03:41 +00:00
Daniil Kalinin
7ccfd3772d PY-72185 disable reparseable leaves by default for further investigation
GitOrigin-RevId: 87a1d99a80415128b303f2b0cb343afd2c939b6a
2024-08-19 16:47:41 +00:00
Andrey Vokin
0beee36468 PY-73099 Support PEP 705 – TypedDict: Read-only items
Check chained TypedDict qualifiers

GitOrigin-RevId: 2e31953d1b238906696e88bc17e29e41972c134f
2024-08-16 16:32:17 +00:00
Ilia Zakoulov
d43e3a74df PY-1751: Introduce completeAllCaretsWithMultipleVariants method to simplify testing
GitOrigin-RevId: 5d09e953381fe924b24a7a429839fd329e543162
2024-08-14 13:37:00 +00:00
Andrey Vokin
11bdced6c0 PY-73099 Support PEP 705 – TypedDict: Read-only items
GitOrigin-RevId: 50d2a1f6e1144f6a7c29ed5f2eb2ab6c1cb1ac64
2024-08-14 11:36:25 +00:00
Petr
1e871fa95f PY-34617 Take into account sys.version_info checks when analyzing Python files
Added test for version-specific stub elements

GitOrigin-RevId: d5adb86a3c93ffb797789ab2e9ba033ec113f98d
2024-08-14 00:17:38 +00:00
Petr
0020fdc7e9 PY-34617 Take into account sys.version_info checks when analyzing Python files
Added test for version-specific stub elements

GitOrigin-RevId: fde82213359e577cb45006d8a795ec8e44129328
2024-08-13 20:39:16 +00:00
Andrey Vokin
1be521e041 PY-73099 Support PEP 705 – TypedDict: Read-only items
GitOrigin-RevId: 24820bf7c9362d3b675ebfca16805744404ac2e9
2024-08-13 06:16:19 +00:00
Andrey Vokin
f4a04d15b6 PY-73099 Support PEP 705 – TypedDict: Read-only items
support for "ReadOnly" qualifier in chain with "Required" and "NotRequired"

GitOrigin-RevId: 4ee6d82f7153d4b65217acb34acc71c4b6c20dc6
2024-08-13 06:16:19 +00:00
Ilya.Kazakevich
b1a4c55771 Python: VirtualEnvReader refactoring: move the same module as PythonSdkUtil, and substitute a couple of methods.
`PythonSdkUtil` duplicates VER logic. One Jython-specific thing was also removed as we do not need Jython anymore

GitOrigin-RevId: 658fc42b485ac074a6d89fce3c7408e51cdc8f95
2024-08-12 20:54:06 +00:00
Petr
a3608ebd22 PY-34617 Remove if stubs
GitOrigin-RevId: 13f49394e92daca80af9c82ac9ac1a439a6ae1f5
2024-08-12 09:37:32 +00:00
Ilya Kazakevich
6d1f3800dd PY-74425: Detect system pythons + pythons on .virtualenvs with NPW
`PythonSdkFlavor` detects pythons.

It uses `VirtualEnvReader` under the hood (see virtual env flavor) and system pythons (see other flavors).

We use it in `PythonLocalAddInterpreterModel` and cover it with tests

PY-74425 WIP, PY-74236: `VirtualEnvReader` shouldn't return `null` nor should it check for dir existence, use `getVEnvRootDir` as a default dir for venv.

The whole logic behind `VirtualEnvReader` is the following: we check for some env variable, and if it points to the correct path -- we use it. We fall back to the home directory otherwise.

Directory doesn't need to exist (hence, no need to check `isDirectory`) because a client might always create it.

Even worse: directory would probably not exist on a fresh OS, but a user still wants to create virtual envs there.

PY-74425 WIP: Encapsulate python names and patterns inside `VirtualEnvReader`.

`VirtualEnvReader` seems to be the main entry point to look for virtual envs on the local file system.

Historically, flavors did that, so they had a set of names and patterns to filter python by name, however:

1. `UnixPythonSdkFlavor` had named for **nix only, and `VirtualEnvSdkFlavor` had names both for Windows and **nix. It is unlikely to see a `.exe ` file on **nix or file, without an extension on Windows, so this check is useless and broken (`VirtualEnvSdkFlavor` checks for both names on both OSes)

2. `UnixPythonSdkFlavor` had regex to filter Python2, but this python was removed 4 years ago and could hardly be met on any new OS; hence this check is useless.

3. New Project Wizard needs to find pythons, but knows nothing about names and patterns.


Merge-request: IJ-MR-142040
Merged-by: Ilya Kazakevich <ilya.kazakevich@jetbrains.com>

GitOrigin-RevId: ce649b4f12f7c7b60a25d8e1fb1222e075337844
2024-08-09 19:46:31 +00:00