import { Range } from '../common/textRange' ; import { ClassNode , ExpressionNode , FunctionNode , ImportAsNode , ImportFromAsNode , ImportFromNode , ModuleNode , NameNode , ParameterNode , ParseNode , RaiseNode , ReturnNode , StringListNode , TypeAnnotationNode , YieldFromNode , YieldNode , } from '../parser/parseNodes' ; export const enum DeclarationType { Intrinsic , Variable , Parameter , Function , Class , SpecialBuiltInClass , Alias } export type IntrinsicType = 'Any' | 'str' | 'str | None' | 'int' | 'Iterable[str]' | 'class' | 'Dict[str, Any]' ; export interface DeclarationBase { type : DeclarationType ; node : ParseNode ; path : string ; range : Range ; moduleName : string ; } export interface IntrinsicDeclaration extends DeclarationBase { type : DeclarationType . Intrinsic ; node : ModuleNode | FunctionNode | ClassNode ; intrinsicType : IntrinsicType ; } export interface ClassDeclaration extends DeclarationBase { type : DeclarationType . Class ; node : ClassNode ; } export interface SpecialBuiltInClassDeclaration extends DeclarationBase { type : DeclarationType . SpecialBuiltInClass ; node : TypeAnnotationNode ; } export interface FunctionDeclaration extends DeclarationBase { type : DeclarationType . Function ; node : FunctionNode ; isMethod : boolean ; isGenerator : boolean ; returnStatements ? : ReturnNode [ ] ; yieldStatements ? : ( YieldNode | YieldFromNode ) [ ] ; raiseStatements ? : RaiseNode [ ] ; } export interface ParameterDeclaration extends DeclarationBase { type : DeclarationType . Parameter ; node : ParameterNode ; } export interface VariableDeclaration extends DeclarationBase { type : DeclarationType . Variable ; node : NameNode | StringListNode ; typeAnnotationNode ? : ExpressionNode | undefined ; inferredTypeSource ? : ParseNode | undefined ; isConstant ? : boolean | undefined ; isFinal ? : boolean ; isClassVar ? : boolean ; isRequired ? : boolean ; isNotRequired ? : boolean ; isDefinedBySlots ? : boolean ; isRuntimeTypeExpression ? : boolean ; typeAliasAnnotation ? : ExpressionNode | undefined ; typeAliasName ? : NameNode | undefined ; isDefinedByMemberAccess ? : boolean ; docString ? : string | undefined ; } export interface AliasDeclaration extends DeclarationBase { type : DeclarationType . Alias ; node : ImportAsNode | ImportFromAsNode | ImportFromNode ; usesLocalName : boolean ; loadSymbolsFromPath : boolean ; symbolName ? : string | undefined ; submoduleFallback ? : AliasDeclaration | undefined ; firstNamePart ? : string | undefined ; implicitImports ? : Map < string , ModuleLoaderActions > ; isUnresolved ? : boolean ; isNativeLib ? : boolean ; } export interface ModuleLoaderActions { path : string ; loadSymbolsFromPath : boolean ; implicitImports ? : Map < string , ModuleLoaderActions > ; } export type Declaration = IntrinsicDeclaration | ClassDeclaration | SpecialBuiltInClassDeclaration | FunctionDeclaration | ParameterDeclaration | VariableDeclaration | AliasDeclaration ; export function isFunctionDeclaration ( decl ) { return decl . type === DeclarationType . Function ; } export function isClassDeclaration ( decl ) { return decl . type === DeclarationType . Class ; } export function isParameterDeclaration ( decl ) { return decl . type === DeclarationType . Parameter ; } export function isVariableDeclaration ( decl ) { return decl . type === DeclarationType . Variable ; } export function isAliasDeclaration ( decl ) { return decl . type === DeclarationType . Alias ; } export function isSpecialBuiltInClassDeclaration ( decl ) { return decl . type === DeclarationType . SpecialBuiltInClass ; } export function isIntrinsicDeclaration ( decl ) { return decl . type === DeclarationType . Intrinsic ; }