@@ -61,17 +61,34 @@ class PythonInlayParameterHintsProvider : InlayParameterHintsProvider {
6161 return inlayInfos
6262 }
6363
64+ var useCallMethod = false
65+ if (resolved is PyTargetExpression ) {
66+ // The target expression might include a lambda or class attribute
67+ val assignedValue = resolved.findAssignedValue() ? : return inlayInfos
68+ resolved = if (assignedValue is PyLambdaExpression && lambdaHints.isEnabled()) {
69+ assignedValue
70+ } else if (assignedValue is PyCallExpression ) {
71+ // Potentially a class instance, very specific and requires more research
72+ useCallMethod = true
73+ assignedValue.callee?.reference?.resolve() ? : return inlayInfos
74+ } else {
75+ return inlayInfos
76+ }
77+ }
78+
6479 var classAttributes = listOf<PyTargetExpression >()
65- if (resolved is PyTargetExpression && lambdaHints.isEnabled()) {
66- // TODO: Handle cases other than lambda expressions
67- // Use the target to find the lambda expression object, and assign it to get its parameters up ahead
68- resolved = PsiTreeUtil .getNextSiblingOfType(resolved, PyLambdaExpression ::class .java) ? : return inlayInfos
69- } else if (resolved is PyClass && classHints.isEnabled()) {
70- // This call is made by a class (initialization), so we want to find the parameters it takes.
80+ if (resolved is PyClass && classHints.isEnabled()) {
81+ // This call is made by a class (instantiation/__call__), so we want to find the parameters it takes.
7182 // In order to do so, we first have to check for an init method, and if not found,
7283 // We will use the class attributes instead. (Handle dataclasses, attrs, etc.)
7384 val evalContext = TypeEvalContext .codeAnalysis(element.project, element.containingFile)
74- val entryMethod = resolved.findInitOrNew(true , evalContext)
85+ val entryMethod = if (useCallMethod) {
86+ // TODO: Find some API sugar to make it more reliable?
87+ resolved.findMethodByName(" __call__" , false , evalContext)
88+ ? : resolved.findInitOrNew(true , evalContext)
89+ } else {
90+ resolved.findInitOrNew(true , evalContext)
91+ }
7592
7693 resolved = if (entryMethod != null && entryMethod.containingClass == resolved) {
7794 entryMethod
0 commit comments