Commit Graph

1658 Commits

Author SHA1 Message Date
Petr
63ccfc1fb1 PY-75537 Slightly simplified PyAssignmentStatementImpl.getTargetsToValuesMapping()
(cherry picked from commit 41f02b5c164380ad978cfa66eb36bb5b97189855)

GitOrigin-RevId: 7f0eec0447f4e39d18b265f86e37a3057d71d9b2
2024-10-18 17:10:51 +00:00
Petr
34a015c9af PY-75537 Implement PyAstAssignmentStatement.getTargets(), PyAstAssignmentStatement.getRawTargets() (PyFrontendElementTypesFacadeImpl.kt)
(cherry picked from commit 0f9292ac3ca0f4f4728b25cb2e5ddcd618b8319d)

GitOrigin-RevId: ced0f2fe8d877e80af4f4568a11cf8ab0f64d57c
2024-10-18 17:10:51 +00:00
Andrey Vokin
63487fda41 PY-75580 Experiment with extended completion
GitOrigin-RevId: 8aeb4c123eb6c8eae3255c974d8630a0745df395
2024-10-14 13:15:14 +00:00
Andrei Iurko
4111cfc875 [qodana] QD-9891 Add aspects with the highest certainty for inspections
GitOrigin-RevId: 8fad66714287192bd5cbc8396a3d30f1ba139302
2024-10-11 14:49:57 +00:00
Gleb Marin
09c2b90e35 [ml imports ranking] Anonymize number of files in py project
FUS-5036 Change group "pycharm.quickfix.imports"


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

GitOrigin-RevId: 278f9c703398a18bc47d2c724d44f12e9ec3610e
2024-10-07 14:14:08 +00:00
Nikolay Chashnikov
88f5f288f9 [python] API cleanup: remove unused deprecated API (IJPL-156972)
GitOrigin-RevId: 57adfe085fe2b77e3c608ba1230688c35b5615d0
2024-10-04 17:44:12 +00:00
Daniil Kalinin
440e53f50b PY-76362 Correctly resolve TypeVar from typing_extensions
GitOrigin-RevId: 9318c0f8b4eece25a427129db7cdcecdf7767dbe
2024-10-04 14:48:11 +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
c5b81e03f3 PY-75760 Refactor the implementation of PEP 696 support - Type Aliases
Refactor the logic of inferring aliased types according to the previous refactoring

GitOrigin-RevId: c03a1533eee0fa6f45fa0f3c2b9ced5e7cc3c336
2024-10-03 12:19:06 +00:00
Daniil Kalinin
23cee33c35 PY-75760 Refactor the implementation of PEP 696 support
1. At first, get rid of the explicit mapping of generics to default types (remove all these not-good-looking methods which were added earlier, such as `PyTypeChecker.trySubstituteByDefaultsOnl`y and `PyTypeChecker.getSubstitutionsWithDefaults`) and their usages. All the related logic now will be handled in `PyTypeParameterMapping`, as we wanted it to be.

2. Do some changes in `PyTypeChecker` to be able to correctly parameterize class via constructor call, and also take defaults into account in `PyTypeChecker.getSubstitutionsWithUnresolvedReturnGenerics` for methods

3. Get rid of the explicit calls of `PyTypingTypeProvider.tryParameterizeClassWithDefaults` in `PyCallExpressionHelper`, `PyReferenceExpressionImpl`, rename this method to `parameterizeClassDefaultAware` and call it directly in `PyTypingTypeProvider.getReferenceType`

4. Add a new flag to `PyTypeParameterMapping` to be able to correctly match type parameters (see `PyTypeChecker.matchTypeParameters`)

GitOrigin-RevId: 5dd90ee3bdf8319b36f1945ce22a33a8edf6bc93
2024-10-03 12:19:06 +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
Andrey Vokin
e3d5629229 PY-75580 Experiment with extended completion
GitOrigin-RevId: ae24082e7b57ea55e35e64b27b26751ec79cdc1d
2024-10-02 14:20:30 +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
Nikita.Ashihmin
b25b4c9950 PY-76193 PyInstall(fix): No missing package warning when only one package is missing
GitOrigin-RevId: f753108a4392afdf7996f73e10becb4fd7b6c76d
2024-09-28 18:22:39 +00:00
Ilia.Kondakov
fe4a6bf3a4 PY-50934 Implement features for ML ordering imports
add new features: info about underscores in path, info about lib location, info about context of original file(extension type, psi parents, size of project),
info about already existing imports from the same library(in this file, in other opened files, in other files in the same directory)

GitOrigin-RevId: ca8206d4d7db6bc79e8f1a78502bf33696a653e9
2024-09-27 10:33:53 +00:00
Irina Fediaeva
c4cb384bb7 PY-75246: Fix quick nav info for file and directory refs
GitOrigin-RevId: b2a6daaebf0f043f1bce2952637bf86c556e8646
2024-09-25 17:53:14 +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
Aleksandr Sorotskii
d67337d2c9 fix additional data creation for remote interpreters; (#PY-76055) Fixed
GitOrigin-RevId: 064cbbaeb5f4241b718c9e51df0396b49971a365
2024-09-23 16:37:06 +00:00
Nikita.Ashihmin
dcd5277ebc PY-76068 PyInspection(fix): Duplicated notification messages if more than 2 imports are unresolved
GitOrigin-RevId: 00e1b88040506118f04e11c03a113e83dc65616f
2024-09-22 21:25:33 +00:00
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