Commit Graph

1589 Commits

Author SHA1 Message Date
Ilya.Kazakevich
fe54db7b3c Python: Remove unused symbols
GitOrigin-RevId: ec2bd2dda3f215a6c318afa70adbccc8627bd586
2024-09-19 17:47:20 +00:00
Tagir Valeev
d013c9980e Remove redundant keySet/values calls
GitOrigin-RevId: e972012a4ead404120b0f947c79d059f6d96f942
2024-09-18 20:27:35 +00:00
Daniil Kalinin
bc9902ad42 [python] fix StackOverflowError while calculating a generic definition type in PyTypingTypeProvider.java
GitOrigin-RevId: 0ff3415886906cb29eb6bd3caa1fa140c0693ba7
2024-09-18 10:41:48 +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
Yuriy Artamonov
7810bf8adb [python] IJPL-158521 Actions: fix ellipsis in messages for actions
GitOrigin-RevId: c896f17db89f934ae64c24b920ed3684b605d168
2024-09-15 14:50:09 +00:00
Ilia Zakoulov
f224638f0f PY-74171 MagicLiteralRenameHandler should not be invoked when it is not magic literal
GitOrigin-RevId: 9d2ce1958c09c8309331dc0bf7229af4b2cdb709
2024-09-13 14:13:53 +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
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
Mikhail Golubev
f927e52bf3 PY-54560 Remove an obsolete TODO
GitOrigin-RevId: 532284b3adb1ef357736880b948cf8fee642ff4c
2024-09-09 23:17:24 +00:00
Vladimir Koshelev
aca9d92e9d [pycharm] introduce cleanAllFileLevelInspections to get rid of getting psi files on EDT for nothing
GitOrigin-RevId: 28acc147cf396d63d27338ce15cab1a6fdfe4a32
2024-09-09 15:50:16 +00:00
Andrey Vokin
0f8e5afa8a PY-73263 Python 3.13 Support - Code Insight - Typeshed
Remove custom deprecation check for abc. Typesheds now have deprecation decorator

GitOrigin-RevId: 72ba0028bfda2d7eda4a8e01aed5962613305531
2024-09-09 13:54:00 +00:00
Andrey Vokin
4c8d95ccc7 [PyCharm] do not refresh packages in test.
Packages refresh leads to enabling dump mode.

GitOrigin-RevId: 253819711787eb74babcbf07ed2c61166f95795e
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
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
132461b7de PyDecoratorImpl.toString() doesn't cause unstubbing
GitOrigin-RevId: a87b3874af518dcaf81384b25b85b76f618bdd1d
2024-09-09 11:34:15 +00:00
Mikhail Golubev
71b010feed Add missing nullability annotations in the PyCustomStub API
GitOrigin-RevId: 2dd1d144d675a2449b2ba3292bfd4fd312b68fea
2024-09-09 11:34:15 +00:00
Mikhail Golubev
f51f790d44 Remove recursive parameterization of PyCustomStub with PyCustomStubType
GitOrigin-RevId: 9377e09058c3a11213ecff3c737c51f0aa5cd127
2024-09-09 11:34:15 +00:00
Daniil Kalinin
038b376423 PY-71002 PEP-696: restore PyGenericType.withTargetExpression method to keep API compatibility
GitOrigin-RevId: af01a057a6d31804410a99fe186b26cb88513f52
2024-09-08 11:36:55 +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
0819e6d3d4 PY-71002 PEP-696: Change PyNewStyleGenericSyntaxInspection.kt according to the previous changes
GitOrigin-RevId: 1885b7e97ef08c71eefb472e582aae97d7464b4b
2024-09-07 11:11:13 +00:00
Daniil Kalinin
cedd61e338 PY-71002 PEP-696: Implement support for defaults in Type Parameters
The changes include:
- Inferring implicitly parameterized types for classes if they are generic classes with type parameters that have defaults.
- Inferring partially parameterized types for classes where only some of the default Type Parameters are overridden by explicit parameterization.
- Supporting both old-style and new-style generic Type Aliases, now considering defaults of Type Parameters.

GitOrigin-RevId: c3a0d7eb4a85585df9638081291ff83b850eb7f6
2024-09-07 11:11:13 +00:00
Daniil Kalinin
003cb6a891 PY-71002 PEP-696: Change type inference of Type Parameters in PyTypingTypeProvider
- Infer default types for TypeVars, ParamSpecs and TypeVarTuples
- Allow explicitly parameterizing ParamSpecs with `[type1, type2, ...]` constructions
- Correctly set declaration elements of Type Parameters inferred from references

GitOrigin-RevId: 024392a03f744e08c6dee054bbc2ca42c1f4b19e
2024-09-07 11:11:13 +00:00
Daniil Kalinin
dd328f3a60 PY-71002 PEP-696: Adapt the interfaces and implementations of Type Parameter types for the support of defaults
In particular:
- Add getters and setters for default types of Type Parameters
- Change the type of declaration elements for Type Parameters from hardcoded PyTargetExpression to PyQualifiedNameOwner to make it possible to set new-style Type Parameters as declaration elements
- Correctly calculate the qualified names of the new-style type alias statements as now they will be used in declaration elements of Type Parameters

GitOrigin-RevId: 5185d85c1a75052dfcb3f97c0eee17b52540d24b
2024-09-07 11:11:12 +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
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
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
8c01fbbebd [python] fix a bug with obtaining ancestor classes in com.jetbrains.python.psi.impl.PyClassImpl.mroLinearize
Fix a bug with a situation when two identical inctances of type `Generic` were stored in the map in `com.jetbrains.python.psi.impl.PyClassImpl.mroLinearize` and were processed separately due to not matching hashcodes and equals methods. This situation caused an `MROException` to be thrown so the class ancestors could not be defined properly. It affected generic types matching as an actually generic class was not recognized as generic because of the wrong list of ancestors.

GitOrigin-RevId: 391390c5143b0c7247bd55f148d519f80063d5a8
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
Vladimir Koshelev
2feb2f4552 [pycharm] cleanup PyTypingTypeProvider
GitOrigin-RevId: a675df9e8d5a0fe05786652c785ef354ec3014b4
2024-09-03 15:26:09 +00:00
Vladimir Koshelev
eb0de2e35a [pycharm] add a stub modification tracker to PyClassNameCompletionContributor to cache all names.
GitOrigin-RevId: c9b5cc51ba119409b65b39b49a7a3ba5fa298873
2024-08-31 20:00:14 +00:00
Nikita.Ashihmin
275ca8b3fc PY-75533 PyPackages(refactor): Install all packages shoundl be hidden if only 1
GitOrigin-RevId: 24a603bff61b699e1fcca4278382b0330a9399a3
2024-08-30 16:39:17 +00:00
Nikita.Ashihmin
2adf643aa9 PY-75533 PyPackages(refactor): Install all packages shoundl be hidden if only 1
GitOrigin-RevId: 4cc00b074c12dd8ef3609e5fd8ec700eaf8fb272
2024-08-30 16:39:16 +00:00
Aleksandr.Govenko
3be9e0e0bb PY-24044 Fix PyCodeFragmentWithHiddenImports
Does not solve the issue yet, but adds proper code fragment with hidden imports

fixup! PY-24044 Fix PyCodeFragmentWithHiddenImports

Changed streams to StringUtil
Changed internal keyword to ApiStatus.Internal

fixup! PY-24044 Fix PyCodeFragmentWithHiddenImports

Convert method to accept a collection of imports

fixup! PY-24044 Fix PyCodeFragmentWithHiddenImports

Mark class as internal

fixup! PY-24044 Fix PyCodeFragmentWithHiddenImports

Remove commented code

fixup! PY-24044 Fix PyCodeFragmentWithHiddenImports

Made publicly exposed collection immutable
Changed PyImportNameDefiner to PyImportedStatementBase
Changed String to List<String>

PY-24044 Fix PyCodeFragmentWithHiddenImports


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

GitOrigin-RevId: bcf28b4a74deeb2adf4d4e53a3c867a9ab7b8ef4
2024-08-29 17:26:42 +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
Andrey Vokin
368a0df14c PY-72690 Slow code analysis for Python code using many TypedDict
Performance snapshot shows that an enormous amount of time is spent calculating hashcodes for types.

GitOrigin-RevId: 47d488ada253c1aa78ae247d45af50cf4a553426
2024-08-28 13:26:25 +00:00
Nikita.Ashihmin
927ebdeddd PY-71152 PyPackage(feat): The dialog picks up unnecessary objects to install, even those that are not packages
GitOrigin-RevId: cc0b5c9e9138b1d68b8ebae5be64c9600d67573b
2024-08-25 09:06:47 +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
Daniil Kalinin
26124892cc PY-75416 disable reparseable statement lists as a workaround
GitOrigin-RevId: d8a5d80fff3886c4f864b2ec82ca8fdf38a9f2b8
2024-08-23 13:54:11 +00:00
Aleksandr.Govenko
9b5b413d45 PY-24044 Evaluate expression and conditional breakpoints should allow adding imports for unresolved names
Added new PyCodeFragmentWithHiddenImports that allows adding imports for unresolved names into a hidden file

GitOrigin-RevId: fb3fa4e491164bdd376d3b25204202034994afa5
2024-08-23 13:37:42 +00:00
Gleb Marin
dc3c5730ea JBAI-5408 Release ML Imports Ranking in 2024.3
[ml tools] Fix build issue

[ml tools] Fix build issue

[ml tools] Fix build issue

[ml tools] Replace task object with service

[ml tools] Fix rebase issues

Add session duration metric

[ml imports ranking] Log fully only during EAP

[ml imports ranking] Set up FUS logs

[ml tools] Add dependency on ml api library


Merge-request: IJ-MR-142857
Merged-by: Gleb Marin <Gleb.Marin@jetbrains.com>

GitOrigin-RevId: 69be00b4b8f38ec71208c3b17cd6566a34508859
2024-08-20 06:16:36 +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
Bernhard Geisberger
174d8e6979 [fleet] [python] FL-28940 Inherit source folder entity sources
This is important because Fleet backend entity sources should all be external

GitOrigin-RevId: 52fe22a004d998f16a2f03be9486cdeb098a4f27
2024-08-15 16:00:12 +00:00
Ilia Zakoulov
a15b7f25b8 PY-1751: Introduce getMethodsInherited for PyClass.
This method collects all methods defined in the class and its parents.
Similar to `getPropertiesInherited` and `getClassAttributesInherited`.

GitOrigin-RevId: 8dcec5a002ffa105083ece6f4418d51e6d8c2879
2024-08-14 13:36:59 +00:00