Commit Graph

1628 Commits

Author SHA1 Message Date
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
Mikhail Golubev
09fa8a0611 [python] Introduce PyArgumentsMapping.isComplete
(cherry picked from commit 64dca74e18a2ae8c4a64f6730093e59dbef6b671)

IJ-CR-146869

GitOrigin-RevId: 42cc87410c38c09a65b38d2ca9389474f17ae8b6
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
0cb148129f [python] dataclass_transform: use the annotated class as a resolve anchor for resolving the field specifiers
(cherry picked from commit f15a07836e7aeac7c46b489b4742e8248a0e6ef4)

GitOrigin-RevId: edf8399741cc5d62ba2fb04f9314eb620f83abae
2024-10-28 20:14:19 +00:00
Daniil Kalinin
24d6509dcd [python] loosen the restrictions on dataclass_transform qualified names
(cherry picked from commit b3e20087b64b159382bc24992efa12b5833d4018)

GitOrigin-RevId: 9f74c1d281fa68d937ad925a865feec29175fe93
2024-10-28 20:14:19 +00:00
Daniil Kalinin
7d891602cf [python] rename __get__ in PyNames.java from GET to DUNDER_GET to avoid confusion
(cherry picked from commit 23dd9bc6cb72630e3bee02a2fb160ff38be17d9a)

GitOrigin-RevId: 94e20ece2828c01019c20ae02663e9bad89a8ff7
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
a7b3aaec00 PY-76629: Do not resolve bundled stubs when the package is not installed
The implementation is very similar to the PyTypeShed,
it should be merged into more general solution.

GitOrigin-RevId: 1449a774e93206349f17f264c27e2a7877d79b19
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
Mikhail Golubev
d69f93c593 PY-76629: Fix DjangoViewNameCompletionTest.testViewNameCompletionInMethods
There were two underlying problems in Kotlin code:
```
run { DjangoFQNamesProvider.ACCEPTS_VIEW_NAME.isNameMatches(this) } != null
```
returned true regardless of the result of `isNameMatches(this)` call.
As a result, we used to suggest Django view names for *all* functions called
"reverse", "redirect" or "reverse_lazy".

Secondly, in FQNamesProviderExtKt.isNameMatches:
```
return getQualifiedNames().any {
  return it.firstComponent == elementQualifiedName.firstComponent &&
         it.lastComponent == elementQualifiedName.lastComponent
}
```
always returned the result of comparison with the first qualified name, ignoring the rest
due to non-local return from the inline `any`.

Finally, DjangoUrlViewProvider.isReverseFunction expected a PyFunctionType as the type
of reverse/redirect/reverse_lazy, but since these functions have overloads in .pyi
stubs we started to infer a union type of PyFunctionTypes for them, breaking the reference
provider. In general, it's better to perform a name resolution instead of type inference
to detect a fully qualified name for a reference.

GitOrigin-RevId: 69949b1b0e65f00557536cf16127279a83ea4f9d
2024-10-28 14:57:56 +00:00
Mikhail Golubev
20b2e20d26 PY-76629 PY-39761 Don't type check __class_getitem__ arguments inside type hints
GitOrigin-RevId: 060a2952d49777bff9853a2d5bc4d257271e559e
2024-10-28 14:57:56 +00:00
Petr
1732354c38 PY-76506 Indexing process should not rely on non-indexed file data in PyCharm 2024.2
(cherry picked from commit 690d2c0c9b044c4132d607e81e770939a3be2315)

GitOrigin-RevId: a524db73b9bd2bdf914e6302460d2a64ab339356
2024-10-28 12:17:15 +00:00
Artem Ivanov
0668846014 PY-74176 Tweak activation of magic literals so they don't interfere with renaming symbols
(cherry picked from commit 69327fbc6680be176286f8fc3dc2aa89140d6c7d)

IJ-MR-146071

GitOrigin-RevId: 37da3ea34c760c7d61384d96616d746a0b731636
2024-10-25 20:18:37 +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
Petr
08c5bfb142 PY-75537 Implement PyAstNamedParameter.getRepr()(PyFrontendElementTypesFacadeImpl.kt)
(cherry picked from commit ef38af29fd176324f4c1bec503a116a5b4f351b4)

GitOrigin-RevId: 9b47c8018c3f8ad04c365175bbeb2791feb966cc
2024-10-18 17:10:51 +00:00
Petr
411f36db5a PY-75537 Implement PyAstStringLiteralExpression.createLiteralTextEscaper() (PyFrontendElementTypesFacadeImpl.kt)
(cherry picked from commit c42b7626a6e57c118e7028a4806bd8fa7938076c)

GitOrigin-RevId: e68adbb728051d49654d76df856b522191330170
2024-10-18 17:10:51 +00:00
Petr
78c67850e3 PY-75537 Implement PyAstStringLiteralExpression.getStringValue(), PyAstStringLiteralExpression.getStringValueTextRange() (PyFrontendElementTypesFacadeImpl.kt)
(cherry picked from commit 372f147a61e07c6cb21aaeb8a7d0f3d14d49417d)

GitOrigin-RevId: 9682c8df1f0acd21580e87d8381995960abeeb8a
2024-10-18 17:10:51 +00:00
Petr
001266a5b7 PY-75537 Implement PyAstAssignmentStatement.getTargetsToValuesMapping() (PyFrontendElementTypesFacadeImpl.kt)
(cherry picked from commit 8c4926689e42f117275986c2e1246d7e04bde489)

GitOrigin-RevId: f83b02700ce17a182807ac8bfe1a0108e09d4741
2024-10-18 17:10:51 +00:00
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