mirror of
https://github.com/microsoft/pyright.git
synced 2024-10-26 10:55:06 +03:00
fixed missing imports inside try/catch blocks when createTypeStub comm… (#4796)
This commit is contained in:
parent
68a8e98ab8
commit
1af9bf8715
@ -324,6 +324,9 @@ export class TypeStubWriter extends ParseTreeWalker {
|
||||
override visitTry(node: TryNode) {
|
||||
// Don't emit a doc string after the first statement.
|
||||
this._emitDocString = false;
|
||||
|
||||
// Only walk a single branch of the try/catch to for imports.
|
||||
this.walk(node.trySuite);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @filename: pyrightconfig.json
|
||||
//// {
|
||||
//// "reportMissingTypeStubs": "warning"
|
||||
//// }
|
||||
|
||||
// @filename: testLib/mylibrary.py
|
||||
// @library: true
|
||||
//// # This is a library file
|
||||
//// class MyLibrary:
|
||||
//// def DoEveryThing(self, code: str):
|
||||
//// ...
|
||||
//// class ExceptLibrary:
|
||||
//// def DoEveryThing(self, code: str):
|
||||
//// ...
|
||||
//// class ElseLibrary:
|
||||
//// def DoEveryThing(self, code: str):
|
||||
//// ...
|
||||
|
||||
// @filename: testLib/__init__.py
|
||||
// @library: true
|
||||
//// try:
|
||||
//// from .mylibrary import MyLibrary
|
||||
//// except:
|
||||
//// from .mylibrary import ExceptLibrary
|
||||
//// else:
|
||||
//// from .mylibrary import ElseLibrary
|
||||
|
||||
// @filename: test.py
|
||||
//// import [|/*marker*/testLi|]b
|
||||
|
||||
const filename4 = helper.getMarkerByName('marker').fileName;
|
||||
const command4 = {
|
||||
title: 'Create Type Stub',
|
||||
command: Consts.Commands.createTypeStub,
|
||||
arguments: ['/', 'testLib', filename4],
|
||||
};
|
||||
|
||||
// @ts-ignore
|
||||
await helper.verifyCommand(command4, {
|
||||
['/typings/testLib/__init__.pyi']: `"""
|
||||
This type stub file was generated by pyright.
|
||||
"""
|
||||
|
||||
from .mylibrary import MyLibrary
|
||||
|
||||
`,
|
||||
});
|
Loading…
Reference in New Issue
Block a user