Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix inlay hints appearing on super() calls #847

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading