Skip to content

Commit

Permalink
fix inlay hints appearing on super() calls
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Nov 5, 2024
1 parent 7032aa3 commit 3fa13a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ export class TypeInlayHintsWalker extends ParseTreeWalker {
// inlay hints for generics
if (
this._settings.genericTypes &&
// where the type is not explicitly specified
node.d.leftExpr.nodeType !== ParseNodeType.Index &&
// where the type is not explicitly specified (theoretically we could show them on all node types that aren't
// `ParseNodeType.Index`, but we don't because it would probably look weird to show them on any other type of expression)
node.d.leftExpr.nodeType === ParseNodeType.Name &&
// don't show them on super calls because that's invalid.
node.d.leftExpr.d.value !== 'super' &&
// only show them on classes, because the index syntax to specify generics isn't valid on functions
isClass(callableType)
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import ClassVar, Final, Unpack
from typing import ClassVar, Final, Unpack, override


foo: Final = int()
Expand All @@ -15,6 +15,8 @@ class Foo[T]:
def __init__(self, value: T) -> None:
self.value = value

def foo(self) -> None: ...

_ = Foo(True)

_ = tuple((1,2,3))
Expand All @@ -23,4 +25,9 @@ class Bar[U, *T]:
def __init__(self, asdf: U,*value: Unpack[T]) -> None:
pass

_ = Bar([1], 1,2,"")
_ = Bar([1], 1,2,"")

class Baz(Foo[int]):
@override
def foo(self) -> None:
return super().foo()
16 changes: 8 additions & 8 deletions packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,42 @@ if (process.platform !== 'win32' || !process.env['CI']) {
expect(result).toStrictEqual([
{
inlayHintType: 'generic',
position: 55,
position: 65,
value: '[int]',
},
{
inlayHintType: 'generic',
position: 126,
position: 136,
value: '[str]',
},
{
inlayHintType: 'generic',
position: 175,
position: 185,
value: '[int]',
},
{
inlayHintType: 'generic',
position: 273,
position: 315,
value: '[bool]',
},
{
inlayHintType: 'parameter',
position: 274,
position: 316,
value: 'value=',
},
{
inlayHintType: 'generic',
position: 290,
position: 332,
value: '[Literal[1, 2, 3], ...]',
},
{
inlayHintType: 'generic',
position: 399,
position: 441,
value: '[list[int], int, int, str]',
},
{
inlayHintType: 'parameter',
position: 400,
position: 442,
value: 'asdf=',
},
]);
Expand Down

0 comments on commit 3fa13a9

Please sign in to comment.