From b405ba163b87bc050632f8ab39751c9b3e29cfda Mon Sep 17 00:00:00 2001 From: Rami Chowdhury Date: Sat, 20 Mar 2021 03:40:11 -0400 Subject: [PATCH] Add "absolute" type names PrintTypeFlag This changes the behavior when printing an object's type to show its "absolute" module path (e.g. `builtins.int` or `asyncio.futures.Future`) rather than the shortened name. --- packages/pyright-internal/src/analyzer/typePrinter.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/pyright-internal/src/analyzer/typePrinter.ts b/packages/pyright-internal/src/analyzer/typePrinter.ts index a66f485c0fdf..df09c2b52770 100644 --- a/packages/pyright-internal/src/analyzer/typePrinter.ts +++ b/packages/pyright-internal/src/analyzer/typePrinter.ts @@ -51,6 +51,10 @@ export const enum PrintTypeFlags { // Include a parentheses around a union if there's more than // one subtype. ParenthesizeUnion = 1 << 4, + + // Include the full name of the module where possible, e.g. + // "builtins.int" rather than "int" + AbsoluteTypeNames = 1 << 5, } export type FunctionReturnTypeCallback = (type: FunctionType) => Type; @@ -448,7 +452,10 @@ export function printObjectTypeForClass( returnTypeCallback: FunctionReturnTypeCallback, recursionCount = 0 ): string { - let objName = type.aliasName || type.details.name; + let objName = + (printTypeFlags & PrintTypeFlags.AbsoluteTypeNames) === 0 + ? type.details.fullName + : type.aliasName || type.details.name; // If this is a pseudo-generic class, don't display the type arguments // or type parameters because it will confuse users.