Skip to content

Commit 13fceb9

Browse files
Morgan Bartholomewintellij-monorepo-bot
authored andcommitted
PY-87791 type engine: fix callable parameter representation type
(cherry picked from commit 7cbc0c26a00a260f8ac9ce4c3ddf18e999e5114e) IJ-MR-192392 GitOrigin-RevId: 65b3919f8073254dad6a631bc5326ae4ad99f6c5
1 parent efa9014 commit 13fceb9

25 files changed

Lines changed: 37 additions & 55 deletions

python/python-psi-impl/src/com/jetbrains/python/codeInsight/typeRepresentation/psi/PyFunctionTypeRepresentation.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,8 @@ class PyFunctionTypeRepresentation(astNode: ASTNode) : PyElementImpl(astNode), P
132132
when (param) {
133133
is PySlashParameter -> PyCallableParameterImpl.psi(param)
134134
is PyNamedParameterTypeRepresentation -> {
135-
val paramName = param.parameterName
136135
val paramType = param.typeExpression?.let { resolveTypeExpression(it, context, typeVarMap) }
137-
PyCallableParameterImpl.nonPsi(paramName, paramType, param.defaultValue)
136+
PyCallableParameterImpl.psi(param, paramType)
138137
}
139138
is PyStarExpression -> {
140139
// *args parameter

python/python-psi-impl/src/com/jetbrains/python/codeInsight/typeRepresentation/psi/PyNamedParameterTypeRepresentation.kt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,14 @@
1616
package com.jetbrains.python.codeInsight.typeRepresentation.psi
1717

1818
import com.intellij.lang.ASTNode
19-
import com.intellij.psi.PsiElement
2019
import com.jetbrains.python.PyTokenTypes
2120
import com.jetbrains.python.psi.PyExpression
22-
import com.jetbrains.python.psi.impl.PyElementImpl
21+
import com.jetbrains.python.psi.impl.PyNamedParameterImpl
2322

24-
class PyNamedParameterTypeRepresentation(astNode: ASTNode) : PyElementImpl(astNode), PsiElement {
23+
class PyNamedParameterTypeRepresentation(astNode: ASTNode) : PyNamedParameterImpl(astNode) {
2524
val parameterName: String?
2625
get() = node.findChildByType(PyTokenTypes.IDENTIFIER)?.text
2726

2827
val typeExpression: PyExpression?
2928
get() = findChildByClass(PyExpression::class.java)
30-
31-
val defaultValue: PyExpression?
32-
get() {
33-
// Find the expression after the = token
34-
val children = node.getChildren(null)
35-
var foundEquals = false
36-
for (child in children) {
37-
if (foundEquals && child.psi is PyExpression) {
38-
return child.psi as PyExpression
39-
}
40-
if (child.elementType == PyTokenTypes.EQ) {
41-
foundEquals = true
42-
}
43-
}
44-
return null
45-
}
4629
}

python/testData/typeRepresentation/parsing/ callable complex varargs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ TypeRepresentation:a.pythonTypeRepresentation
44
PsiElement(Py:LPAR)('(')
55
PyStarExpression
66
PsiElement(Py:MULT)('*')
7-
PyNamedParameterTypeRepresentation
7+
PyNamedParameterTypeRepresentation('a')
88
PsiElement(Py:IDENTIFIER)('a')
99
PsiElement(Py:COLON)(':')
1010
PsiWhiteSpace(' ')
@@ -26,7 +26,7 @@ TypeRepresentation:a.pythonTypeRepresentation
2626
PsiWhiteSpace(' ')
2727
PyDoubleStarExpression
2828
PsiElement(Py:EXP)('**')
29-
PyNamedParameterTypeRepresentation
29+
PyNamedParameterTypeRepresentation('b')
3030
PsiElement(Py:IDENTIFIER)('b')
3131
PsiElement(Py:COLON)(':')
3232
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ callable default parameter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TypeRepresentation:a.pythonTypeRepresentation
22
PyFunctionTypeRepresentation
33
PyParameterListRepresentation
44
PsiElement(Py:LPAR)('(')
5-
PyNamedParameterTypeRepresentation
5+
PyNamedParameterTypeRepresentation('a')
66
PsiElement(Py:IDENTIFIER)('a')
77
PsiElement(Py:COLON)(':')
88
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ callable named parameter.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TypeRepresentation:a.pythonTypeRepresentation
22
PyFunctionTypeRepresentation
33
PyParameterListRepresentation
44
PsiElement(Py:LPAR)('(')
5-
PyNamedParameterTypeRepresentation
5+
PyNamedParameterTypeRepresentation('a')
66
PsiElement(Py:IDENTIFIER)('a')
77
PsiElement(Py:COLON)(':')
88
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ callable without type parameter list.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ TypeRepresentation:a.pythonTypeRepresentation
22
PyFunctionTypeRepresentation
33
PyParameterListRepresentation
44
PsiElement(Py:LPAR)('(')
5-
PyNamedParameterTypeRepresentation
5+
PyNamedParameterTypeRepresentation('x')
66
PsiElement(Py:IDENTIFIER)('x')
77
PsiElement(Py:COLON)(':')
88
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ function type with all parameter types.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ TypeRepresentation:a.pythonTypeRepresentation
88
PsiElement(Py:IDENTIFIER)('f')
99
PyParameterListRepresentation
1010
PsiElement(Py:LPAR)('(')
11-
PyNamedParameterTypeRepresentation
11+
PyNamedParameterTypeRepresentation('pos')
1212
PsiElement(Py:IDENTIFIER)('pos')
1313
PsiElement(Py:COLON)(':')
1414
PsiWhiteSpace(' ')
@@ -20,7 +20,7 @@ TypeRepresentation:a.pythonTypeRepresentation
2020
PsiElement(Py:DIV)('/')
2121
PsiElement(Py:COMMA)(',')
2222
PsiWhiteSpace(' ')
23-
PyNamedParameterTypeRepresentation
23+
PyNamedParameterTypeRepresentation('normal')
2424
PsiElement(Py:IDENTIFIER)('normal')
2525
PsiElement(Py:COLON)(':')
2626
PsiWhiteSpace(' ')
@@ -30,15 +30,15 @@ TypeRepresentation:a.pythonTypeRepresentation
3030
PsiWhiteSpace(' ')
3131
PyStarExpression
3232
PsiElement(Py:MULT)('*')
33-
PyNamedParameterTypeRepresentation
33+
PyNamedParameterTypeRepresentation('args')
3434
PsiElement(Py:IDENTIFIER)('args')
3535
PsiElement(Py:COLON)(':')
3636
PsiWhiteSpace(' ')
3737
PyReferenceExpression: float
3838
PsiElement(Py:IDENTIFIER)('float')
3939
PsiElement(Py:COMMA)(',')
4040
PsiWhiteSpace(' ')
41-
PyNamedParameterTypeRepresentation
41+
PyNamedParameterTypeRepresentation('kw')
4242
PsiElement(Py:IDENTIFIER)('kw')
4343
PsiElement(Py:COLON)(':')
4444
PsiWhiteSpace(' ')
@@ -48,7 +48,7 @@ TypeRepresentation:a.pythonTypeRepresentation
4848
PsiWhiteSpace(' ')
4949
PyDoubleStarExpression
5050
PsiElement(Py:EXP)('**')
51-
PyNamedParameterTypeRepresentation
51+
PyNamedParameterTypeRepresentation('kwargs')
5252
PsiElement(Py:IDENTIFIER)('kwargs')
5353
PsiElement(Py:COLON)(':')
5454
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ function type with complex varargs.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TypeRepresentation:a.pythonTypeRepresentation
1010
PsiElement(Py:LPAR)('(')
1111
PyStarExpression
1212
PsiElement(Py:MULT)('*')
13-
PyNamedParameterTypeRepresentation
13+
PyNamedParameterTypeRepresentation('args')
1414
PsiElement(Py:IDENTIFIER)('args')
1515
PsiElement(Py:COLON)(':')
1616
PsiWhiteSpace(' ')
@@ -27,7 +27,7 @@ TypeRepresentation:a.pythonTypeRepresentation
2727
PsiWhiteSpace(' ')
2828
PyDoubleStarExpression
2929
PsiElement(Py:EXP)('**')
30-
PyNamedParameterTypeRepresentation
30+
PyNamedParameterTypeRepresentation('kwargs')
3131
PsiElement(Py:IDENTIFIER)('kwargs')
3232
PsiElement(Py:COLON)(':')
3333
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ function type with default values.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ TypeRepresentation:a.pythonTypeRepresentation
88
PsiElement(Py:IDENTIFIER)('f')
99
PyParameterListRepresentation
1010
PsiElement(Py:LPAR)('(')
11-
PyNamedParameterTypeRepresentation
11+
PyNamedParameterTypeRepresentation('a')
1212
PsiElement(Py:IDENTIFIER)('a')
1313
PsiElement(Py:COLON)(':')
1414
PsiWhiteSpace(' ')
1515
PyReferenceExpression: int
1616
PsiElement(Py:IDENTIFIER)('int')
1717
PsiElement(Py:COMMA)(',')
1818
PsiWhiteSpace(' ')
19-
PyNamedParameterTypeRepresentation
19+
PyNamedParameterTypeRepresentation('b')
2020
PsiElement(Py:IDENTIFIER)('b')
2121
PsiElement(Py:COLON)(':')
2222
PsiWhiteSpace(' ')

python/testData/typeRepresentation/parsing/ function type with kwargs.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ TypeRepresentation:a.pythonTypeRepresentation
1010
PsiElement(Py:LPAR)('(')
1111
PyDoubleStarExpression
1212
PsiElement(Py:EXP)('**')
13-
PyNamedParameterTypeRepresentation
13+
PyNamedParameterTypeRepresentation('kwargs')
1414
PsiElement(Py:IDENTIFIER)('kwargs')
1515
PsiElement(Py:COLON)(':')
1616
PsiWhiteSpace(' ')

0 commit comments

Comments
 (0)