Skip to content
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
5 changes: 5 additions & 0 deletions packages/pyright-internal/src/analyzer/importResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1209,6 +1209,11 @@ export class ImportResolver {
execEnv.pythonPlatform
)
) {
// typeshed says that 'typing_extensions' is stdlib
// so we fix that with this special case
if (moduleName === 'typing_extensions') {
importType = ImportType.ThirdParty;
}
return {
moduleName,
importType,
Expand Down
44 changes: 44 additions & 0 deletions packages/pyright-internal/src/tests/completions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,50 @@ describe('useTypingExtensions', () => {
});
});

test('typing_extensions auto-import should be placed in third-party section', async () => {
const code = `
// @filename: pyrightconfig.json
//// { "pythonVersion": "3.10" }

// @filename: test.py
//// from unittest import TestCase[|/*importMarker*/|]
////
//// [|override/*marker*/|]
`;

const state = parseAndGetTestState(code).state;

// If it's stdlib, it will be placed alphabetically before unittest (old bugged behavior)
await state.verifyCompletion(
'included',
'markdown',
{
['marker']: {
completions: [
{
label: 'override',
kind: CompletionItemKind.Function,
detail: 'Auto-import',
textEdit: {
range: state.getPositionRange('marker'),
newText: 'override',
},
additionalTextEdits: [
{
range: state.getPositionRange('importMarker'),
newText: '\n\nfrom typing_extensions import override',
},
],
},
],
},
},
undefined,
undefined,
false
);
});

test('import from stdlib package', async () => {
const code = `
// @filename: test.py
Expand Down
Loading