Commit Graph

4573 Commits

Author SHA1 Message Date
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
Pavel Karateev
85c6eee402 PY-75714 Fold single line match case clauses
Merge-request: IJ-MR-144163
Merged-by: Pavel Karateev <Pavel.Karateev@jetbrains.com>

GitOrigin-RevId: 352d1111988371b6edd9fa1af71b345dbb7aee38
2024-10-02 15:01:14 +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
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
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
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
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
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
d5bf0d0ae2 PY-54560 Fix typos in a test
GitOrigin-RevId: f544f217d7a59b62d3a2a793097e6021ea771f03
2024-09-09 23:17:24 +00:00
Andrey Vokin
7b9531711d PY-73263 Python 3.13 Support - Code Insight - Typeshed
Update testdata

GitOrigin-RevId: 73eca86671bcacd7efbdd305925abf1882590fd3
2024-09-09 13:54:00 +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
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
53d8170407 PY-59198 Update attr package stubs in test data
GitOrigin-RevId: 1292ba4fb7f39a2980b30c80d16811060f11509c
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
Mikhail Golubev
132461b7de PyDecoratorImpl.toString() doesn't cause unstubbing
GitOrigin-RevId: a87b3874af518dcaf81384b25b85b76f618bdd1d
2024-09-09 11:34:15 +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
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
Daniil Kalinin
e9db83e006 PY-26184 switch the first letters of the names of test directories to uppercase
GitOrigin-RevId: 09812f6c256fbebf96fe16985895430c3804f6e7
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
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
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
Mikhail Golubev
c685dbd6aa PY-49174 Add a missing test counterpart for Jupyter, remove redundant indent in test data
GitOrigin-RevId: f8975cc051cdeff7d0708e3031e9f64e8e175a06
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
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
Petr
a3608ebd22 PY-34617 Remove if stubs
GitOrigin-RevId: 13f49394e92daca80af9c82ac9ac1a439a6ae1f5
2024-08-12 09:37:32 +00:00
Peter Gromov
59e0ddc429 IJPL-90547 Suppress missing-space errors in chained references embedded into text
GitOrigin-RevId: 15b545318fb80b90fb7d3c9cae605ebc07729b0a
2024-08-05 21:14:24 +00:00
Ilya.Kazakevich
e75a7f2f83 Python tests: migrate tox 37->39 (37 is outdated)
GitOrigin-RevId: 8592221541a2a7512d559184bd352dabef5b657c
2024-07-31 10:18:57 +00:00
Ilya.Kazakevich
ccd804fe9c Python tests: migrate tox 37->39 (37 is outdated)
GitOrigin-RevId: 1d8588f3785940c1cbe4036c8a475853f19a79c5
2024-07-31 08:20:14 +00:00
Petr
93b9066edf PY-34617 Support version check
GitOrigin-RevId: 3318ff79cdcc5ba0ce5e4feb65abad5ad0f4acfa
2024-07-28 00:24:15 +00:00
Egor Eliseev
994775243f PY-71926 Refine test detection criteria
Add a new setting Python Integrated Tools: Detect tests in Jupyter Notebooks.
Exclude Jupyter Notebook files from the scope for test detection by default.
Add tests


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

GitOrigin-RevId: 0bee082bde4fa608cb1907b8fbd64b97bb9755a0
2024-07-26 17:24:30 +00:00
Petr
5470f70382 PY-73886 PyArgumentListInspection causes file parsing
GitOrigin-RevId: 8fa6b52a2ac5d28e7148c3e10445ee61fef6c89b
2024-07-25 01:35:16 +00:00
Mikhail Golubev
f392777e01 PY-44858 Create regular packages in refactorings initiated from top-level files in source/content roots
Otherwise, if someone wants to move a definition/extract a superclass from there to
a brand-new package, e.g. from main.py to pkg/mod.py, a namespace "pkg" package will
be created.

Restore the original behavior of PyExtractSuperclassTest.testMultifileNew: the origin
file was inside a regular project root without __init__.py alongside.

GitOrigin-RevId: 750414b18582740076c14bfcfd07fa38992b4428
2024-07-24 16:18:40 +00:00
Mikhail Golubev
1c026ac470 PY-44858 Make multifile scenarios comparing directory content in PyExtractSuperclassTests more uniform
Now they all just compare the resulting test project content with an explicit "after" directory
instead of checking individual files in the test code.

GitOrigin-RevId: cff00d0a6b8ea4547b719997716e95a3f7c62cc9
2024-07-24 16:18:40 +00:00
maxle
90bbc21f3f PY-44858 Move and other refactorings don't introduce __init__.py inside namespace packages
Namely, Move Module Members, Extract Superclass and Make Local Function Top-Level were
all affected by this.
Now we check if the refactoring origin is inside a namespace package to decide whether
__init__.py should be generated for target directories.

Co-authored-by: Kamalia <alishevakamalia@gmail.com>
Co-authored-by: Maksim.Levitskii <maksim.levitskii@jetbrains.com>

GitOrigin-RevId: b0b3420c5ec8d1f7d3000d8834211631690a0c42
2024-07-24 16:18:40 +00:00
Andrey Vokin
e6c66dfd5e PY-74012 Deprecation decorator stub resolves during indexing
Avoid using resolve when calculating deprecation messages

GitOrigin-RevId: 813849bdaeb3819b445db600fc0efbcb014ed5c9
2024-07-19 19:18:54 +00:00
chbndrhnns
c274285cae PY-66043: Resolve module references in PYTEST_PLUGINS
close #2814


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

GitOrigin-RevId: 4a7d46178ceedc283345980f118fbe607d84e685
2024-07-17 15:38:34 +00:00
Daniil Kalinin
e9a6246df3 PY-72185 Implement incremental parsing for PSI leaves for Python
Merge-request: IJ-MR-138193
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: 7d004677a5b7a4637ea956f13ed85abc0d88604e
2024-07-17 12:15:36 +00:00
Vladimir Koshelev
82e8947e95 [pycharm] move type guards from control flow to PyDefUse stage
GitOrigin-RevId: e66971e619978ad179bb49a15820a7482b27df7c
2024-07-15 18:43:02 +00:00
Vladimir Koshelev
582edda2e8 [pycharm] fix control flow tests after adding CallInstruction
GitOrigin-RevId: 1878a3211a07b216a64df3efa6ac7cb1c94fd246
2024-07-10 14:22:00 +00:00