зеркало из https://github.com/microsoft/pyright.git
Fixed a bug in the stub generator so it properly outputs type aliases that use the PEP 613 `TypeAlias` qualifier.
This commit is contained in:
Родитель
9c52b15619
Коммит
b2fc167735
|
@ -48,7 +48,15 @@ import { SourceFile } from './sourceFile';
|
|||
import { Symbol } from './symbol';
|
||||
import * as SymbolNameUtils from './symbolNameUtils';
|
||||
import { TypeEvaluator } from './typeEvaluatorTypes';
|
||||
import { ClassType, isFunction, isInstantiableClass, isNever, isUnknown, removeUnknownFromUnion } from './types';
|
||||
import {
|
||||
ClassType,
|
||||
isClassInstance,
|
||||
isFunction,
|
||||
isInstantiableClass,
|
||||
isNever,
|
||||
isUnknown,
|
||||
removeUnknownFromUnion,
|
||||
} from './types';
|
||||
|
||||
class TrackedImport {
|
||||
isAccessed = false;
|
||||
|
@ -427,6 +435,16 @@ export class TypeStubWriter extends ParseTreeWalker {
|
|||
} else if (node.d.leftExpr.nodeType === ParseNodeType.TypeAnnotation) {
|
||||
const valueExpr = node.d.leftExpr.d.valueExpr;
|
||||
|
||||
const declaredType = this._evaluator.getTypeOfAnnotation(node.d.leftExpr.d.annotation, {
|
||||
varTypeAnnotation: true,
|
||||
allowClassVar: true,
|
||||
});
|
||||
|
||||
// Is this an explicit TypeAlias declaration?
|
||||
if (isClassInstance(declaredType) && ClassType.isBuiltIn(declaredType, 'TypeAlias')) {
|
||||
isTypeAlias = true;
|
||||
}
|
||||
|
||||
if (valueExpr.nodeType === ParseNodeType.Name) {
|
||||
if (this._functionNestCount === 0) {
|
||||
line = `${this._printExpression(valueExpr)}: ${this._printExpression(
|
||||
|
|
Загрузка…
Ссылка в новой задаче