Skip to content

Commit

Permalink
don't show inlay hints on assignments to _
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Mar 18, 2024
1 parent 818853d commit 280778d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
5 changes: 4 additions & 1 deletion packages/pyright-internal/src/analyzer/symbolNameUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ export function isSingleDunderName(name: string) {
return name.length > 2 && name.startsWith('_') && name.endsWith('_');
}

/** underscore-only names mean a value is being intentionally ignored */
export const isUnderscoreOnlyName = (name: string) => name.match(_underscoreOnlyRegEx);

// Constants are all-caps with possible numbers and underscores.
export function isConstantName(name: string) {
return !!name.match(_constantRegEx) && !name.match(_underscoreOnlyRegEx);
return !!name.match(_constantRegEx) && !isUnderscoreOnlyName(name);
}

// Type aliases are CamelCase with possible numbers and underscores.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParseTreeWalker } from '../analyzer/parseTreeWalker';
import { isDunderName } from '../analyzer/symbolNameUtils';
import { isDunderName, isUnderscoreOnlyName } from '../analyzer/symbolNameUtils';
import { FunctionType, Type, isAny, isClass, isParamSpec, isTypeVar } from '../analyzer/types';
import { ProgramView } from '../common/extensibility';
import { limitOverloadBasedOnCall } from '../languageService/tooltipUtils';
Expand Down Expand Up @@ -82,7 +82,7 @@ export class TypeInlayHintsWalker extends ParseTreeWalker {
}

override visitName(node: NameNode): boolean {
if (isLeftSideOfAssignment(node) && !isDunderName(node.value)) {
if (isLeftSideOfAssignment(node) && !isDunderName(node.value) && !isUnderscoreOnlyName(node.value)) {
const type = this._program.evaluator?.getType(node);
if (
type &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
foo = 1 # no inlay hint because Literal
T = TypeVar(name="T") # no inlay hint because typevar
U = TypeVar(name="U", bound=Function) # no inlay hint because typevar
P = ParamSpec(name="P") # no inlay hint because paramspec
P = ParamSpec(name="P") # no inlay hint because paramspec
_ = str(1) # no inlay hint because underscore only variable

0 comments on commit 280778d

Please sign in to comment.