File tree Expand file tree Collapse file tree
packages/pyright-internal/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1209,6 +1209,11 @@ export class ImportResolver {
12091209 execEnv . pythonPlatform
12101210 )
12111211 ) {
1212+ // typeshed says that 'typing_extensions' is stdlib
1213+ // so we fix that with this special case
1214+ if ( moduleName === 'typing_extensions' ) {
1215+ importType = ImportType . ThirdParty ;
1216+ }
12121217 return {
12131218 moduleName,
12141219 importType,
Original file line number Diff line number Diff line change @@ -2343,6 +2343,50 @@ describe('useTypingExtensions', () => {
23432343 } ) ;
23442344} ) ;
23452345
2346+ test ( 'typing_extensions auto-import should be placed in third-party section' , async ( ) => {
2347+ const code = `
2348+ // @filename: pyrightconfig.json
2349+ //// { "pythonVersion": "3.10" }
2350+
2351+ // @filename: test.py
2352+ //// from unittest import TestCase[|/*importMarker*/|]
2353+ ////
2354+ //// [|override/*marker*/|]
2355+ ` ;
2356+
2357+ const state = parseAndGetTestState ( code ) . state ;
2358+
2359+ // If it's stdlib, it will be placed alphabetically before unittest (old bugged behavior)
2360+ await state . verifyCompletion (
2361+ 'included' ,
2362+ 'markdown' ,
2363+ {
2364+ [ 'marker' ] : {
2365+ completions : [
2366+ {
2367+ label : 'override' ,
2368+ kind : CompletionItemKind . Function ,
2369+ detail : 'Auto-import' ,
2370+ textEdit : {
2371+ range : state . getPositionRange ( 'marker' ) ,
2372+ newText : 'override' ,
2373+ } ,
2374+ additionalTextEdits : [
2375+ {
2376+ range : state . getPositionRange ( 'importMarker' ) ,
2377+ newText : '\n\nfrom typing_extensions import override' ,
2378+ } ,
2379+ ] ,
2380+ } ,
2381+ ] ,
2382+ } ,
2383+ } ,
2384+ undefined ,
2385+ undefined ,
2386+ false
2387+ ) ;
2388+ } ) ;
2389+
23462390test ( 'import from stdlib package' , async ( ) => {
23472391 const code = `
23482392// @filename: test.py
You can’t perform that action at this time.
0 commit comments