diff --git a/packages/pyright-internal/src/tests/samples/inlay_hints/generics.py b/packages/pyright-internal/src/tests/samples/inlay_hints/generics.py index 4bb8b4554..64996e1a7 100644 --- a/packages/pyright-internal/src/tests/samples/inlay_hints/generics.py +++ b/packages/pyright-internal/src/tests/samples/inlay_hints/generics.py @@ -7,4 +7,12 @@ class Foo: a: ClassVar = "asdf" - b: ClassVar[str] = "asdf" \ No newline at end of file + b: ClassVar[str] = "asdf" + +_ = list([1]) + +class Foo[T]: + def __init__(self, value: T) -> None: + self.value = value + +_ = Foo("") \ No newline at end of file diff --git a/packages/pyright-internal/src/tests/testUtils.ts b/packages/pyright-internal/src/tests/testUtils.ts index da44d6456..f92a61f91 100644 --- a/packages/pyright-internal/src/tests/testUtils.ts +++ b/packages/pyright-internal/src/tests/testUtils.ts @@ -32,6 +32,7 @@ import { SemanticTokenItem, SemanticTokensWalker } from '../analyzer/semanticTok import { TypeInlayHintsItemType, TypeInlayHintsWalker } from '../analyzer/typeInlayHintsWalker'; import { Range } from 'vscode-languageserver-types'; import { ServiceProvider } from '../common/serviceProvider'; +import { InlayHintSettings } from '../common/languageServerInterface'; // This is a bit gross, but it's necessary to allow the fallback typeshed // directory to be located when running within the jest environment. This @@ -147,13 +148,17 @@ export const semanticTokenizeSampleFile = (fileName: string): SemanticTokenItem[ return walker.items; }; -export const inlayHintSampleFile = (fileName: string, range?: Range): TypeInlayHintsItemType[] => { +export const inlayHintSampleFile = ( + fileName: string, + range?: Range, + settings: Partial = {} +): TypeInlayHintsItemType[] => { const program = createProgram(); const fileUri = UriEx.file(resolveSampleFilePath(path.join('inlay_hints', fileName))); program.setTrackedFiles([fileUri]); const walker = new TypeInlayHintsWalker( program, - { callArgumentNames: true, functionReturnTypes: true, variableTypes: true, genericTypes: true }, + { callArgumentNames: true, functionReturnTypes: true, variableTypes: true, genericTypes: false, ...settings }, fileUri, range ); diff --git a/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts b/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts index 11d9da43a..d0cbef38e 100644 --- a/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts +++ b/packages/pyright-internal/src/tests/typeInlayHintsWalker.test.ts @@ -78,7 +78,7 @@ if (process.platform !== 'win32' || !process.env['CI']) { ]); }); test('generics', () => { - const result = inlayHintSampleFile('generics.py'); + const result = inlayHintSampleFile('generics.py', undefined, { genericTypes: true }); expect(result).toStrictEqual([ { inlayHintType: 'generic', @@ -90,6 +90,16 @@ if (process.platform !== 'win32' || !process.env['CI']) { position: 118, value: '[str]', }, + { + inlayHintType: 'generic', + position: 167, + value: '[int]', + }, + { + inlayHintType: 'generic', + position: 265, + value: '[bool]', + }, ]); }); } else {