Skip to content

Commit f04c70d

Browse files
committed
Support __new__ method
1 parent c472430 commit f04c70d

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
### Fixed
99
- Hints showing when placing a positional argument after keyword ones
10+
- Hints for classes that use `__new__`, like `datetime.datetime`
1011

1112
## [0.1.2] - 2022-07-18
1213
### Fixed

src/main/kotlin/space/whitememory/pythoninlayparams/PythonInlayHintsProvider.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ class PythonInlayHintsProvider : InlayParameterHintsProvider {
5151
// In order to do so, we first have to check for an init method, and if not found,
5252
// We will use the class attributes instead. (Handle dataclasses, attrs, etc.)
5353
val evalContext = TypeEvalContext.codeAnalysis(element.project, element.containingFile)
54-
val initMethod = resolved.findMethodByName("__init__", false, evalContext)
55-
resolved = if (initMethod != null) {
56-
initMethod
54+
val entryMethod = resolved.findInitOrNew(true, evalContext)
55+
56+
resolved = if (entryMethod != null && entryMethod.containingClass == resolved) {
57+
entryMethod
5758
} else {
5859
// Use the class attributes if there's no init with params in the parent classes
5960
// TODO: Make sure wrong attributes are not used
6061
classAttributes = resolved.classAttributes
61-
resolved.findMethodByName("__init__", true, evalContext) ?: resolved
62+
entryMethod ?: resolved
6263
}
6364
}
6465

0 commit comments

Comments
 (0)