333 Commits

Author SHA1 Message Date
Nikolay Chashnikov
f17fa8da08 [python] get rid of references to package-private members of intellij.python.psi.* modules from other modules (IJPL-149126)
GitOrigin-RevId: 8cc01d6fd600b59b8da814638d9da8df69975ad5
2025-04-30 09:01:10 +00:00
Aleksandr.Govenko
a757828b06 PY-76659 Make CFG traversal iterative for name resolution and type inference
Swap back to ConcurrentMap and add more Registry checks

softValueMap doesn't play well with assumeType. Imagine this: you compute type A and store it, then compute type B that depends on A. But since softValueMap uses soft references, A might get garbage-collected. If that happens, you can override A with assumeType, and now B is out of sync — it's still based on the old version of A.

This kind of issue is unlikely to show up in small, artificial examples, but it could easily become a problem in real-world projects, especially large ones. It breaks the assumption that if a type is in the map, then everything it depends on should still be there too.

fix after rebase

Added nullability annotations to the AssumptionContext constructor parameters to improve type safety.

dm-checkpoint-id: 1VH4Od1GtvAo

Squash for easier rebase


Co-authored-by: Space Team <noreply@jetbrains.team>

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

GitOrigin-RevId: cf2fc232c2c5b35a037396b5f85be3129a5efd3a
2025-04-20 16:03:28 +00:00
Vladimir Krivosheev
a5132e5922 fix TypeEvalConstraints visibility
GitOrigin-RevId: 8f3d15b28a69854937e77e05e84b70e902671e77
2025-04-08 16:05:15 +00:00
Mikhail Golubev
fb6554a342 [python] Move TypeEvalContextCacheImpl to intellij.python.psi.impl, leaving TypeEvalContextCache in intellij.python.psi
It will allow moving the implementation of TypeEvalContext to intellij.python.psi.impl
as well, making more platform and Python plugin APIs available in it.

GitOrigin-RevId: c04a2dc4d892d213f5407bcce35aeb5a3aba42dc
2025-04-07 17:07:46 +00:00
Mikhail Golubev
b619e21989 [python] Remove TypeEvalContextBasedCache
GitOrigin-RevId: 74d87561c3cc857ede78e60f19a7edbad35f29ee
2025-04-07 17:07:46 +00:00
Aleksandr.Govenko
624cedaa60 PY-79675 Pattern matching for dataclass fields
Merge-request: IJ-MR-155072
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: 3cf0c311a5e4a273d289d73f17c3d418e608df21
2025-04-06 01:17:47 +00:00
Daniil Kalinin
3f6d195e1f PY-79842 Remove the assertion which emits a user-visible exception
GitOrigin-RevId: 9a0ea6b8c961424dd5008658a1b1ca16067b9a67
2025-04-02 11:49:38 +00:00
Andrey Vokin
8c1f3b6efa PY-78304 Use SoftReference to store types in TypeEvalContext
cleanup

GitOrigin-RevId: e9b24b1b27c24b29a389d08ede0358cbb33bbe8b
2025-03-26 10:53:48 +00:00
Andrey Vokin
d55cd9563c PY-78304 Use SoftReference to store types in TypeEvalContext
Make PyNullType class private

GitOrigin-RevId: 39c4e6f581c48419c82404944a67de154abd3bf3
2025-03-26 10:53:48 +00:00
Andrey Vokin
6a5d65a5de PY-78304 Use SoftReference to store types in TypeEvalContext
GitOrigin-RevId: d0e2c405ff0bec6fd9b677a55255929f8100217a
2025-03-26 10:53:48 +00:00
evgeny.bovykin
bf6e4735b6 PY-46623 Refactor PyKnownDecorator and related classes to be extendable
PyKnownDecorator is now a class instead of an enum, allowing extension to create new instances

GitOrigin-RevId: 846617f68e559f7f77af15a999f837391ac3090e
2025-03-14 15:15:09 +00:00
Aleksandr.Govenko
0073c7a8bb PY-48011 Pattern Matching: Type inference
Merge-request: IJ-MR-154823
Merged-by: Aleksandr Govenko <aleksandr.govenko@jetbrains.com>

GitOrigin-RevId: 42cb07bee63f34127c85574fc9c09e6043bc7591
2025-03-07 22:56:00 +00:00
Petr
405b37ac93 [python] Minor code deduplication
GitOrigin-RevId: 9ffcd59ab6810970b0f595fe9e1a721f83997812
2025-02-21 13:48:33 +00:00
Mikhail Golubev
d5e40b4ad4 PY-78236 Rename PyTypeVisitor#visitPyType to just #visit, add javadoc
Similarly to PyRecursiveTypeVisitor#traverse and PyCloningTypeVisitor#clone.

GitOrigin-RevId: 285537e4b7f9326ded81dcd648fa510572c0aba3
2025-02-14 18:53:22 +00:00
Mikhail Golubev
7ae73ebeb6 PY-78236 Introduce PyTypeVisitor API
GitOrigin-RevId: b6aa236b364bc55840be0a148205abba9c22167b
2025-02-14 18:53:22 +00:00
Leonid Shalupov
e4e5753846 housekeeping: remove unused imports
GitOrigin-RevId: ccba6d05260f5eb551ffa87e0d8a38dc93148a3a
2025-02-04 11:00:15 +00:00
Petr
af57462aa7 PY-78653 Fix constrained type variable substitution
Subtypes of types constrained by a type variable should be treated as their respective explicitly listed base types in the context of the type variable.

GitOrigin-RevId: ecaac1614f66974b6e6c2217ac0a90321d049f76
2025-01-28 15:24:40 +00:00
Ilya.Kazakevich
29ec21d7bd Python: unused symbols removed
GitOrigin-RevId: ea7dc3c43777f2b33e3284f782620ae8cdef04a2
2025-01-26 00:20:34 +00:00
Mikhail Golubev
ffb28d92c9 [python] Add a comment explaining the meaning of TypeEvalContext.Key
GitOrigin-RevId: eddc81498f070efffb79c0698bb30e69f35b289b
2025-01-22 16:49:41 +00:00
Daniil Kalinin
f05119cead [python] Store default types of Type Parameters as Ref to avoid problems with an explicit Any
GitOrigin-RevId: 880e883d196dc48d9cf6400580e9b4981448c507
2025-01-08 14:05:26 +00:00
Vladimir Krivosheev
0bc1cf1557 update bazel files
GitOrigin-RevId: 7320d3eff3aba093692ce66839c720ece6d7c4db
2024-12-30 11:28:24 +00:00
Vladimir Krivosheev
7b9ec58009 do not export intellij.database.connectivity.tests
GitOrigin-RevId: a1ef44dfa34cde110c9e6cad19d11b5e3019ab72
2024-12-28 21:45:55 +00:00
Vladimir Krivosheev
68d99c6550 cleanup
GitOrigin-RevId: 9cb238c220249088bfc75a448eb310b93c7fc45c
2024-12-26 14:56:01 +00:00
Petr
49b3258737 PY-76812 Conformance test failure: typeddicts_alt_syntax.py
Infer typed dict type from TypedDict() call even in case of an unexpected arguments list.

Also changed incorrect TypedDict() signature:
from (name: str, fields: dict[str, Any], total: bool = True) -> Any
to (typename: str, fields: dict[str, type], *, /, total: bool = True) -> Any

GitOrigin-RevId: 94c1ebb4fe3026744cb9771eab9e5ba507d049fa
2024-12-19 18:50:44 +00:00
Ilia Zakoulov
e044f9e441 PY-39384: Introduce PyTypeHintProvider
`PyTypeHintProvider` allows providing type hints for resolved elements before the main logic of `PyTypingTypeProvider`.
See an example of `django-stubs`: https://github.com/typeddjango/django-stubs/pull/2335.
`_UserModel` type might be replaced with a custom user model, provided in `settings.py` (`AUTH_USER_MODEL`).

GitOrigin-RevId: 986fb91c800be3ccfbc002c73c673896efec8a1a
2024-12-17 14:12:23 +00:00
Vladimir Krivosheev
98799639aa do not use _test as lib - test targets do not support this
GitOrigin-RevId: f2f49db4294b6a64040dbbd5f1d95e972cbd70a3
2024-12-15 18:32:30 +00:00
Aleksandr.Govenko
80ea4e852c PY-20710 Support 'Generator' typing class
Check YieldType of yield expressions in PyTypeCheckerInspection
Check that (Async)Generator is used in (async) function
Check that in 'yield from' sync Generator is used
Convert PyMakeFunctionReturnTypeQuickFix into PsiUpdateModCommandAction
Infer Generator type for lambdas
When getting function type from annotation, do not convert Generator to AsyncGenerator
Introduce GeneratorTypeDescriptor to simplify working with generator annotations


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

GitOrigin-RevId: b3b8182168c5224f0e03f54d443171ccf6ca7b89
2024-12-04 15:22:15 +00:00
Vladimir Krivosheev
17916c90f8 libraries -> lib, resources, opt-in, test deps
GitOrigin-RevId: db66ee95dcb0f0553b40c9cc56cd6afed8634cdd
2024-11-27 13:53:42 +00:00
Aleksandr.Govenko
31dd92576e PY-20611 Missing warning about functions implicitly returning None when return type is not Optional
Updated PyFunction to account for implicit 'return None' statements when inferring return statement types.

It affected return type inference of PyFunction.

Fixed a failing test related to formatted strings.

Added a quick fix to make all return statements explicit.

Updated the CFG to include PyPassStatements, enabling detection of exit points in empty functions.

Simplified PyMakeFunctionReturnTypeQuickFix to independently infer function types and handle required imports. Currently, it does not support specifying custom suggested types.



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

GitOrigin-RevId: 9f58961f9eb70e4f9dbba7359f5aafdfd392b7e2
2024-11-26 17:02:37 +00:00
Mikhail Golubev
b0bb5138f7 PY-77538 Introduce PyCallableParameterListType and PyCallableParameterVariadicType interface
PyCallableParameterListType type represents a concrete list of PyCallableParameters that
a PyParamSpecType can be specialized with.

Now PyParamSpecType and PyCallableParameterListType are similar to PyTypeVarTupleType and
PyUnpackedTupleType (a type parameter and its concrete specialization).

PyCallableParameterVariadicType indicates types that PyParamSpecType can be specialized with.
Namely, another PyParamSpecType, PyCallableParameterListType and PyConcatenateType.

GitOrigin-RevId: cc254b64884e637c1200f6334b6680ea3444bb8a
2024-11-21 11:26:23 +00:00
Mikhail Golubev
816845add5 PY-77538 Extract PyPositionalVariadicType marker interface
that indicates types compatible with PyTypeVarTupleType: PyTypeVarTupleType and
PyUnpackedTupleType. It will allow introducing a counterpart interface for types
compatible with PyParamSpecType.

GitOrigin-RevId: 0d5c77dd21d2bc7a21b246cfbd951cdd096918e9
2024-11-21 11:26:23 +00:00
Petr
16d40e9c5d PY-76830 PY-76833 PY-76843 PY-76879 Enums support
GitOrigin-RevId: 9021c003cde70c39f8a5635b42761c08049490e2
2024-11-13 18:30:03 +00:00
Mikhail Golubev
414397c7ea PY-77167 Simplify resolve logic for overloads, get rid of RatedResolveResult#RATE_LIFTED_PY_FILE_OVERLOAD
If there is an overload not followed by an implementation, which is
already an error, always resolve to the first overload, regardless
of whether it's a .py file, or a .pyi stub. It allows us to eliminate
the special RatedResolveResult#RATE_LIFTED_PY_FILE_OVERLOAD rate in .py
files, because we no longer need to duplicate the last, closest reachable
overload (normally an implementation should be reachable) with a higher
priority, and then filter it out during overload resolution.

Meanwhile, this filtering out didn't work right before
because some type inference logic, e.g., PyCallExpressionHelper.getCalleeType
used in PyReferenceExpressionImpl.getCallableType bypassed it. It should have
been done at the level of
PyCallExpressionHelper.forEveryScopeTakeOverloadsOtherwiseImplementations.

GitOrigin-RevId: 99a624ab85957d7a2d3c2c0ced596e472f9d615b
2024-11-05 12:33:52 +00:00
Artem Ivanov
1f08f46354 PY-74176 Allow PyTargetExpression along with PyReferenceExpression to hold Constance references
GitOrigin-RevId: 1b4a1c2c24f0aedbb6782aedfca02e119aabcd59
2024-10-25 16:27:08 +00:00
Ilya.Kazakevich
be826ca3b4 PY-75549: Simple (aka scratch) project first implementation.
Enable `pycharm.scratchProject`, and go to welcome screen.

GitOrigin-RevId: 9190344e3e8c1e7eb40834ad30c3e8f75dd599fe
2024-10-24 19:44:26 +00:00
Petr
9034b13880 PY-75537 Implement PyAstNamedParameter.getRepr()(PyFrontendElementTypesFacadeImpl.kt)
GitOrigin-RevId: ef38af29fd176324f4c1bec503a116a5b4f351b4
2024-10-16 10:54:46 +00:00
Petr
a1c0baf9c5 PY-75537 Implement PyAstStringLiteralExpression.getStringValue(), PyAstStringLiteralExpression.getStringValueTextRange() (PyFrontendElementTypesFacadeImpl.kt)
GitOrigin-RevId: 372f147a61e07c6cb21aaeb8a7d0f3d14d49417d
2024-10-16 10:54:46 +00:00
Petr
5befce7fb9 PY-75537 Implement PyAstAssignmentStatement.getTargetsToValuesMapping() (PyFrontendElementTypesFacadeImpl.kt)
GitOrigin-RevId: 8c4926689e42f117275986c2e1246d7e04bde489
2024-10-16 10:54:46 +00:00
Mikhail Golubev
33919a56d0 [python] Introduce PyArgumentsMapping.isComplete
GitOrigin-RevId: 64dca74e18a2ae8c4a64f6730093e59dbef6b671
2024-10-15 22:19:26 +00:00
Nikolay Chashnikov
b03b560520 [python] API cleanup: mark deprecated unused API for removal (IJPL-156972)
Deprecated APIs which still have internal usage are marked as internal to ensure that new external usages won't appear.

GitOrigin-RevId: 09818b884851d7b768f8ee0f356f982e79b46ed9
2024-10-10 23:55:42 +00:00
Artem Ivanov
66fb06fcd9 PY-74171 Inherit PyKeywordArgument and PyReferenceExpression from PsiExternalReferenceHost
This allows using Symbol API to create references in PyKeywordArgument or PyReferenceExpression elements.

GitOrigin-RevId: 19545edec1499de66fb7744e7f8e3cb7f4ea85d3
2024-09-13 14:13:53 +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
143b893f2c PY-34617 Take into account sys.version_info checks when analyzing Python files
Don't use PyAst* interfaces in PyVersionCheck.kt

GitOrigin-RevId: 6179220a0821a5e93a90938867e842d68ed9f2b0
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
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
Vladimir Koshelev
8f1f5d99a4 [pycharm] create PyNarrowedType explicitly for TypeGuard and TypeIs PY-74277
GitOrigin-RevId: fe01878d76473c3c149ca520bf7978be49bfd097
2024-08-23 17:26:21 +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
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