Commit Graph

1384 Commits

Author SHA1 Message Date
Georgii Ustinov
10964f31fc Improve public API in PyQuotedStringIntention
PY-65297

GitOrigin-RevId: 6965f9b558ca278708c39e9ed37ec7b629f8554a
2024-02-12 16:48:35 +00:00
Georgii Ustinov
ad7870a802 Adapt PyQuotedStringIntention to use as public API
PY-65297

GitOrigin-RevId: 0d5184be120393144eaf10c66d7dd2c1ed219ede
2024-02-12 12:17:43 +00:00
Petr Golubev
25b8ebcf83 PY-61639 Extracted PythonEnterHandler
GitOrigin-RevId: 8fd0c063c917e07c3f1bf98533c3de867f770ee9
2024-02-08 13:58:08 +00:00
Petr Golubev
1a73bd2d21 PY-61639 Extracted PyAstElementGenerator
GitOrigin-RevId: 915c235120b079188d81efaa9ccf9728131fa3df
2024-02-08 13:58:08 +00:00
Petr Golubev
c90db007c0 PY-61639 Lift PyFile.getTopLevelAttributes(), PyFile.findTopLevelAttribute() to PyAstFile
GitOrigin-RevId: 373accde23bb2c55d1d23266da7874e34da96ea3
2024-02-08 13:58:08 +00:00
Petr Golubev
f818966298 PY-61639 Lift PyParameter.isSelf() method to PyAstParameter
GitOrigin-RevId: 919518e5d06f2b968974bfdbd8deea2ced03c822
2024-02-08 13:58:08 +00:00
Petr Golubev
223013dad1 PY-61639 Introduced PyAstElementVisitor
GitOrigin-RevId: 6ee69922a4ade172dba5abb3ea3b13d01c2b0ebc
2024-02-08 13:58:08 +00:00
Mikhail Golubev
2c1f92d396 [python] Cleanup in PyStringConcatenationToFormatIntention
- use more modern API where applicable
- give more descriptive names to variables and methods
- remove unnecessary abstraction of Lists as Collections
- remove a usage of PyClassTypeImpl
- remove a redundant counter variable
- remove casts
- remove now discouraged final modifiers
- add nullability annotations

GitOrigin-RevId: bfcd08760d1901417a6f662f8ea0205351fd28e5
2024-02-07 17:34:54 +00:00
Mikhail Golubev
454deac682 [python] Fix PyStringConcatenationToFormatIntention for enclosing string concatenations
Noticed in IJ-CR-123777.

GitOrigin-RevId: f32832bca10e805fc609babf81382709d58fc480
2024-02-07 17:34:49 +00:00
Mikhail Golubev
c432ce7605 [python] Reformat PyStringConcatenationToFormatIntention
GitOrigin-RevId: 05130866b9bc3d80d2fa6a66a0241b4fd8ab9c1e
2024-02-07 17:34:43 +00:00
Mikhail Golubev
442c4a0408 [python] Don't re-create TypeEvalContext and LanguageLevel in PyStringConcatenationToFormatIntention
GitOrigin-RevId: c108290dba1057068480709787d356929860551d
2024-02-07 17:34:38 +00:00
Mikhail Golubev
d542f769ef [python] Remove redundant getContainingFile() calls for LanguageLevel.forElement(psiElement)
GitOrigin-RevId: 7000722c4aa3243b80556268d7221ecfea10910f
2024-02-07 17:34:33 +00:00
Mikhail Golubev
b55fd53258 PY-35627 Make Python formatter always add a line break after a decorator list
For regular non-async functions, it already worked thanks to PyTokenSeparatorGenerator.

GitOrigin-RevId: b60dba7b34710cad7dc46ad6f943b3944fc00c42
2024-02-07 17:34:28 +00:00
lada.gagina
6b89cfb4d2 [python] Stop replacing underscore with hyphen for requirements (PY-65170)
GitOrigin-RevId: ad7f3c578f797d974d73b82100f530591daab53d
2024-01-29 19:57:08 +00:00
Daniil Kalinin
c79da2708c PY-64074 Add Quick Documentation for type parameters and type alias statements
Merge-request: IJ-MR-119974
Merged-by: Daniil Kalinin <Daniil.Kalinin@jetbrains.com>

GitOrigin-RevId: fa0c57b3005b31d892a394b3a5f595ac10135a71
2024-01-23 09:50:49 +00:00
Alexandr Suhinin
79653f2633 CR-101244 clean up: remove redundant overriding methods
GitOrigin-RevId: d4d165c6280b7bead925940c82b20f5300c7750a
2024-01-20 15:47:17 +00:00
Vladimir Koshelev
aec2051aa9 [python] get rid of IStubElementType and move logic about working with stubs to impl classes PY-61639
GitOrigin-RevId: 062dead109c25d944d4f61e901dc3c64c00b392e
2024-01-19 23:14:49 +00:00
Petr Golubev
05484d8f97 PY-53120 "Add method" action does not create async def
GitOrigin-RevId: 8b2286a3f50d7b0d00ebbb0befc9811a80f7b304
2024-01-19 20:06:59 +00:00
Tagir Valeev
4b41b4d7de Fix warnings
GitOrigin-RevId: 7f254921acad08c7a2b6192b4e6b8aed5bb29c47
2024-01-19 11:20:43 +00:00
Petr Golubev
b3c3216f79 PY-61639: Extracted python ast
GitOrigin-RevId: 4fc0ae909811302d8425f1e67d8c648c290afcb3
2024-01-17 17:23:01 +00:00
Ilya.Kazakevich
b533e29ce0 [python] get rid of classes registered in wrong modules
You must register class in the same v2 module class sits

GitOrigin-RevId: c7fcccd27c2fcaa3d9391d1173f61ad43fe2b076
2024-01-17 04:59:01 +00:00
Georgii Ustinov
f8b666c6cd Specify more precisely elements for some ModCommand based actions, remove file type check, hide startInWriteAction
PY-62597

GitOrigin-RevId: d2bd27cbc0f6197d4c9cfbb55fa23351f255aa18
2024-01-15 13:15:57 +00:00
Georgii Ustinov
369953fbd2 Specify more precisely elements for some ModCommand based actions and remove IntentionFamilyName annotation from key
PY-62597

GitOrigin-RevId: 486a50119c13e1d204bd13f63bf0786a84d54408
2024-01-15 13:15:48 +00:00
Georgii Ustinov
1ee87451b8 Migrate PyBaseConvertCollectionLiteralIntention to ModCommand
PY-65297

GitOrigin-RevId: 992f7104f83136b1bb2c47d29a83dc482bcf15b2
2024-01-12 16:07:38 +00:00
Georgii Ustinov
85810b8e83 Migrate PyConvertToFStringIntention to ModCommand
PY-65297

GitOrigin-RevId: b8323699fe45068a330662e78052decd6035b919
2024-01-12 12:53:18 +00:00
Georgii Ustinov
16c24031a3 Migrate PyConvertTripleQuotedStringIntention and PyDemorganIntention to ModCommand
PY-65297

GitOrigin-RevId: 900c8ac1568a0d97e7365cf63e7c554d57a76708
2024-01-12 12:53:11 +00:00
Georgii Ustinov
1ca8156c65 Migrate PyDictConstructorToLiteralFormIntention, PyDictLiteralFormToConstructorIntention, PyFlipComparisonIntention
PY-65297

GitOrigin-RevId: 535ec8dce4ecb5933f840fb6237ecec1b9ed07ad
2024-01-12 12:53:04 +00:00
Georgii Ustinov
83a345e0ba Migrate PyInvertIfConditionIntention, PyNegateComparisonIntention, PyQuotedStringIntention to ModCommand
PY-65297

GitOrigin-RevId: b6fcd76c1f21cbf7b17e11ca4690be6f9742faba
2024-01-12 12:52:58 +00:00
Georgii Ustinov
183c37f41e Migrate PyConvertImportIntentionActio and ReplaceListComprehensionWithForIntention to ModCommand
PY-65297

GitOrigin-RevId: e5aa826a816c3d302a7f70f005ba6688449bde10
2024-01-12 12:52:51 +00:00
Georgii Ustinov
fb31a3e184 Migrate PyStringConcatenationToFormatIntention to ModCommand
PY-65297

GitOrigin-RevId: c70ff45bfee111408b44aa903c353eba6df895c3
2024-01-12 12:52:44 +00:00
Georgii Ustinov
f8990a192d Migrate CompatibilityPrintCallQuickFix, PyTransformConditionalExpressionIntention and PyYieldFromIntention to ModCommand
PY-65297

GitOrigin-RevId: f77789cecd5d8d83e33242b7e800b63b00dafe1e
2024-01-12 12:52:37 +00:00
Mikhail Golubev
d6275fee56 [python] Rename PyVariableAnnotator to PyLocalVariableAnnotator
GitOrigin-RevId: 3915187122fc37bea44ca983b685dbfa0f65d725
2024-01-12 11:52:18 +00:00
Mikhail Golubev
f9bb539137 [python] Speed up and extend PyVariableAnnotator
Traversing through all children of a PyFunction looking for nested functions,
possibly declaring a nonlocal or global variable, and doing that for every
target expression or a reference to one, is both inefficient and seemingly
hardly needed. For a name being local means that it cannot be accessed
outside the scope of the corresponding function. Updating this variable from
some inner helper function doesn't violate this property. In Python, one
has to explicitly mark a name from an enclosing scope as nonlocal or global to
be able to assign to it within a function. It seems enough (and less surprising)
to rely on this information to distinguish between local variables and everything
else.

All in all, if some local variable is accessed as a nonlocal name in an inner
function, it's now still highlighted as local in the function that defines
it (previously it wasn't), but it is not in the function declaring it as
nonlocal (same as before).

Additionally, we now uniformly highlight as local variables "for" and "with"
statement targets, targets of assignment expressions, names bound in patterns,
and variables in assignments with unpacking (previously it was done only for
trivial assignments).

GitOrigin-RevId: 04c07ae6814a6b531911b3d87a3a26191c934962
2024-01-12 11:52:08 +00:00
Ilya.Kazakevich
e4a56dc87f [python] PythonPsiApiIcons moved to com.jetbrains.python package, as whole community.python.impl must be there
GitOrigin-RevId: 0c38ddbdd5b0588ed4ec09c1d447248678974323
2024-01-11 20:29:55 +00:00
Ilya.Kazakevich
f8a5625f99 [python] packages moved to com.jetbrains.python package, as whole community.python.impl must be there
GitOrigin-RevId: 339a5be4b4c260ce0c31ee2245870ef953065b2d
2024-01-11 20:29:48 +00:00
Mikhail Golubev
fa168f4a00 PY-36444 Remove @contextlib.contextmanager from PyKnownDecoratorUtil.KnownDecorator
This decorator is fully type hinted in Typeshed, so, with the changes introduced
for PY-60104, it's no longer necessary to special-case it anywhere.
PyDecoratedFunctionTypeProvider can infer the correct type after application
of this decorator to a generator function just as for any other typed decorator.

The original problem was caused by the fact that PyDecoratedFunctionTypeProvider
didn't process declarations having any decorator listed in the KnownDecorator enum,
as presumably all of them were too "magical" to analyze.

Co-authored-by: Daniil Kalinin <daniil.kalinin@jetbrains.com>

GitOrigin-RevId: 53b277803a1eb42784131d0dae5bb7ace173c017
2024-01-09 20:49:13 +00:00
Mikhail Golubev
3079150697 PY-60104 Don't try to infer side effects of not type hinted decorators
Assume that such decorators as well as "well-known" decorators, which we special-case,
don't change signatures of decorated functions and classes.

This change effectively stops the long-standing policy of safe-listing a few recognized
"well-known" decorators and assuming everything else can change a definition in any
way. This approach doesn't apply well to the current state of the Python world, where most
of the common side effects of decorators, such as adding new parameters, can be expressed
in type hints.

In 2021.1 we added PyDecoratedFunctionTypeProvider that was able to infer a return type of
decorator over its body, as for any other function, and then correctly apply this information
to a decorated definition. It led to a number of problems.

First of all, depending on whether TypeEvalContext allowed us to access AST of a decorator's
body, we inferred different signatures for functions decorated with an imported decorator in
inspections and in user-initiated actions, such as Parameter Info.

Secondly, we started inferring useless `(*args, **kwargs)` signatures in case of decorators
defined following the common pattern of returning a wrapper function accepting arbitrary
parameters and itself decorated with @functools.wraps (PY-48338). In some sense, our code
analysis was "too smart" in its type inference in this case.

Lastly, we diluted the return types of functions decorated with unknown decorators, even
fully typed, by uniting these types with Any (so-called "weak" types). This logic
existed before PyDecoratedFunctionTypeProvider, but it became more problematic now
than we were able to propagate this artificial union through generic decorators.

This change in behavior might lead to some false positives for untyped Python code
with non-pure decorators. However, given that other type checkers are also likely to hit these
problems, there is now a stronger incentive to add type hints for such problematic APIs.
In the worst case, we can special-case some heavily requested decorators as we did before.

GitOrigin-RevId: db11fb3573bda5da155cb921a30adc31d5c841e2
2024-01-09 20:49:13 +00:00
andrey.matveev
52f21cc60d PY-48338 PY-60104 Make decorators pure functions if not annotated
GitOrigin-RevId: fed5c22c9114a5dcfb882be367c570baf8ba3e5a
2024-01-09 20:49:13 +00:00
Ilya.Kazakevich
0bb35f314f Move ext classes to the correct package
GitOrigin-RevId: 7caba83654fff8b721a5c7c238f582358af7eebe
2024-01-09 03:00:22 +00:00
Ilya.Kazakevich
66856780b6 Move NNP to the correct package
GitOrigin-RevId: 741f097ea8f599a182f8b44ae0e55fee15e7b09f
2024-01-09 03:00:16 +00:00
Ilya.Kazakevich
7d6afbdf7e Move tensorflow to the correct package as everything must be in com.jetbrains.python in this module
GitOrigin-RevId: e684b59a25303e4ed7f41a109a58bc424a532c1d
2024-01-09 03:00:09 +00:00
Ilya.Kazakevich
fc2c5e4389 Move numpy to the correct package as it sits inside of includable module
GitOrigin-RevId: 3f697f59e60c11b03a1cc04649b864d510310cd3
2024-01-09 03:00:02 +00:00
Georgii Ustinov
e904a3fe51 Migrate AddParameterQuickFix and PyJoinIfIntention to ModCommand
PY-65297

GitOrigin-RevId: 6ed09dbd203e8267472b13298c40a143595d2696
2024-01-08 17:23:49 +00:00
Georgii Ustinov
841df0c0a2 Remove old template builder and assert on valid psi in StatementEffectIntroduceVariableQuickFix
PY-65297

GitOrigin-RevId: 62ab94ec16f9cce0ac7606c5da48422d7512dc5e
2024-01-08 17:23:43 +00:00
Georgii Ustinov
76691e44e9 Migrate RenameParameterQuickFix and StatementEffectIntroduceVariableQuickFix to ModCommand
PY-65297

GitOrigin-RevId: 8d9763a3039f26ab65557721682ce9f409e7f72b
2024-01-08 08:42:52 +00:00
Georgii Ustinov
4d2e4a3197 Migrate UnresolvedReferenceAddSelfQuickFix to ModCommand
PY-65297

GitOrigin-RevId: 4265fda32fa1fe27fe04e7cdea98840cc90c7eee
2024-01-05 09:10:51 +00:00
Georgii Ustinov
007259a141 Migrate PyReplaceTupleWithListQuickFix and UnresolvedRefTrueFalseQuickFix to ModCommand
PY-65297

GitOrigin-RevId: e0abfb5676823e1a70d5aac605da7844ca170ee4
2024-01-05 09:10:47 +00:00
Georgii Ustinov
bf7b728383 Migrate RemovePrefixQuickFix and RemoveTrailingSuffixQuickFix to ModCommand
PY-65297

GitOrigin-RevId: a1ce25b66db97aec5aa3cdc6b15f521628971814
2024-01-05 09:10:43 +00:00
Georgii Ustinov
cf043445b0 Migrate RemoveUnnecessaryBackslashQuickFix and ReplaceBackquoteExpressionQuickFix to ModCommand
PY-65297

GitOrigin-RevId: 4ce00d9b64e1ec4df6ef95784df9f9cd54e21dfa
2024-01-05 09:10:39 +00:00
Georgii Ustinov
9beee6f18c Migrate ReplaceBuiltinsQuickFix and ReplaceExceptPartQuickFix to ModCommand
PY-65297

GitOrigin-RevId: 0c64bd5e5f4fb68f0d41640896470d429865b3d2
2024-01-05 09:10:35 +00:00