Skip to content

Commit

Permalink
Add "absolute" type names PrintTypeFlag
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
necaris committed Mar 20, 2021
1 parent 535ed3a commit b405ba1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/pyright-internal/src/analyzer/typePrinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b405ba1

Please sign in to comment.