Skip to content

Commit

Permalink
Removed fragile hack that was previously added to handle type var sco…
Browse files Browse the repository at this point in the history
…ping for the synthesized constructor in a named tuple. (#5560)

Co-authored-by: Eric Traut <[email protected]>
  • Loading branch information
erictraut and msfterictraut authored Jul 21, 2023
1 parent 37f8149 commit 2b420cf
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 8 deletions.
1 change: 1 addition & 0 deletions packages/pyright-internal/src/analyzer/namedTuples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function createNamedTupleType(
if (ParseTreeUtils.isAssignmentToDefaultsFollowingNamedTuple(errorNode)) {
constructorType.details.flags |= FunctionTypeFlags.DisableDefaultChecks;
}
constructorType.details.typeVarScopeId = classType.details.typeVarScopeId;
FunctionType.addParameter(constructorType, {
category: ParameterCategory.Simple,
name: 'cls',
Expand Down
8 changes: 0 additions & 8 deletions packages/pyright-internal/src/analyzer/typeEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9074,14 +9074,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
if (!effectiveTypeVarContext) {
// If a typeVarContext wasn't provided by the caller, allocate one here.
effectiveTypeVarContext = new TypeVarContext(getTypeVarScopeIds(expandedCallType));

// There are certain cases, such as with super().__new__(cls) calls where
// the call is a constructor but the proper TypeVar scope has been lost.
// We'll add a wildcard TypeVar scope here. This is a bit of a hack and
// we may need to revisit this in the future.
if (FunctionType.isConstructorMethod(expandedCallType)) {
effectiveTypeVarContext.addSolveForScope(WildcardTypeVarScopeId);
}
}

const functionResult = validateFunctionArguments(
Expand Down

0 comments on commit 2b420cf

Please sign in to comment.