Skip to content

Commit 9949577

Browse files
committed
Removed provisional support for PEP 677 (Alternate Call Syntax) because the proposal was rejected by the Python steering council.
1 parent ef72e40 commit 9949577

15 files changed

+8
-642
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Pyright supports [configuration files](/docs/configuration.md) that provide gran
3030
* [PEP 655](https://www.python.org/dev/peps/pep-0655/) required typed dictionary items
3131
* [PEP 673](https://www.python.org/dev/peps/pep-0673/) Self type
3232
* [PEP 675](https://www.python.org/dev/peps/pep-0675/) arbitrary literal strings
33-
* [PEP 677](https://www.python.org/dev/peps/pep-0677/) callable type syntax
3433
* [PEP 681](https://www.python.org/dev/peps/pep-0681/) dataclass transform
3534
* Type inference for function return values, instance variables, class variables, and globals
3635
* Type guards that understand conditional code flow constructs like if/else statements

packages/pyright-internal/src/analyzer/parseTreeUtils.ts

-22
Original file line numberDiff line numberDiff line change
@@ -433,25 +433,6 @@ export function printExpression(node: ExpressionNode, flags = PrintExpressionFla
433433
case ParseNodeType.Set: {
434434
return node.entries.map((entry) => printExpression(entry, flags)).join(', ');
435435
}
436-
437-
case ParseNodeType.ArrowCallable: {
438-
const paramsText = node.parameters.map((param) => {
439-
let prefix = '';
440-
if (param.category === ParameterCategory.VarArgList) {
441-
prefix = '*';
442-
} else if (param.category === ParameterCategory.VarArgDictionary) {
443-
prefix = '**';
444-
}
445-
446-
const typeText = printExpression(param.typeAnnotation);
447-
448-
return `${prefix}${typeText}`;
449-
});
450-
451-
const optionalAsync = node.isAsync ? 'async ' : '';
452-
453-
return `${optionalAsync}(${paramsText.join(', ')}) -> ${printExpression(node.returnTypeAnnotation)}`;
454-
}
455436
}
456437

457438
return '<Expression>';
@@ -1762,9 +1743,6 @@ export function printParseNodeType(type: ParseNodeType) {
17621743

17631744
case ParseNodeType.PatternClassArgument:
17641745
return 'PatternClassArgument';
1765-
1766-
case ParseNodeType.ArrowCallable:
1767-
return 'ArrowCallable';
17681746
}
17691747

17701748
assertNever(type);

packages/pyright-internal/src/analyzer/parseTreeWalker.ts

-11
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import { fail } from '../common/debug';
1111
import {
1212
ArgumentNode,
13-
ArrowCallableNode,
1413
AssertNode,
1514
AssignmentExpressionNode,
1615
AssignmentNode,
@@ -572,12 +571,6 @@ export class ParseTreeWalker {
572571
}
573572
break;
574573

575-
case ParseNodeType.ArrowCallable:
576-
if (this.visitArrowCallable(node)) {
577-
return [...node.parameters.map((param) => param.typeAnnotation), node.returnTypeAnnotation];
578-
}
579-
break;
580-
581574
default:
582575
fail('Unexpected node type');
583576
break;
@@ -591,10 +584,6 @@ export class ParseTreeWalker {
591584
return true;
592585
}
593586

594-
visitArrowCallable(node: ArrowCallableNode) {
595-
return true;
596-
}
597-
598587
visitAssert(node: AssertNode) {
599588
return true;
600589
}

packages/pyright-internal/src/analyzer/typeEvaluator.ts

+1-138
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { TextRange } from '../common/textRange';
2828
import { Localizer } from '../localization/localize';
2929
import {
3030
ArgumentCategory,
31-
ArrowCallableNode,
3231
AssignmentNode,
3332
AugmentedAssignmentNode,
3433
BinaryOperationNode,
@@ -1071,11 +1070,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
10711070
break;
10721071
}
10731072

1074-
case ParseNodeType.ArrowCallable: {
1075-
typeResult = getTypeFromArrowCallable(node, flags);
1076-
break;
1077-
}
1078-
10791073
case ParseNodeType.Assignment: {
10801074
typeResult = getTypeOfExpression(node.rightExpression);
10811075
assignTypeToExpression(
@@ -11457,136 +11451,6 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
1145711451
return type;
1145811452
}
1145911453

11460-
function getTypeFromArrowCallable(node: ArrowCallableNode, flags: EvaluatorFlags): TypeResult {
11461-
// Emit an error if this will cause a runtime exception.
11462-
const fileInfo = AnalyzerNodeInfo.getFileInfo(node);
11463-
if (
11464-
!fileInfo.isStubFile &&
11465-
fileInfo.executionEnvironment.pythonVersion < PythonVersion.V3_11 &&
11466-
(flags & EvaluatorFlags.NotParsedByInterpreter) === 0
11467-
) {
11468-
addError(Localizer.Diagnostic.arrowCallableIllegal(), node);
11469-
}
11470-
11471-
const isIncomplete = false;
11472-
const functionType = FunctionType.createInstantiable('', '', '', FunctionTypeFlags.None);
11473-
11474-
const enclosingScope = ParseTreeUtils.getEnclosingClassOrFunction(node);
11475-
11476-
// Handle the case where the Callable has no enclosing scope. This can
11477-
// happen in the case where a generic function return type is annotated
11478-
// with a generic type alias that includes a Callable in its definition.
11479-
functionType.details.typeVarScopeId = enclosingScope
11480-
? getScopeIdForNode(enclosingScope)
11481-
: WildcardTypeVarScopeId;
11482-
11483-
const returnAnnotationOptions: AnnotationTypeOptions = {};
11484-
if ((flags & EvaluatorFlags.AssociateTypeVarsWithCurrentScope) !== 0) {
11485-
returnAnnotationOptions.associateTypeVarsWithScope = true;
11486-
}
11487-
if ((flags & EvaluatorFlags.NotParsedByInterpreter) !== 0) {
11488-
returnAnnotationOptions.notParsedByInterpreter = true;
11489-
}
11490-
11491-
let returnType = getTypeOfAnnotation(node.returnTypeAnnotation, returnAnnotationOptions);
11492-
if (node.isAsync) {
11493-
functionType.details.flags |= FunctionTypeFlags.Async;
11494-
const awaitableType = getTypingType(node, 'Awaitable');
11495-
if (awaitableType && isInstantiableClass(awaitableType)) {
11496-
returnType = ClassType.cloneForSpecialization(
11497-
ClassType.cloneAsInstance(awaitableType),
11498-
[returnType],
11499-
/* isTypeArgumentExplicit */ true
11500-
);
11501-
} else {
11502-
returnType = UnknownType.create();
11503-
}
11504-
}
11505-
11506-
functionType.details.declaredReturnType = returnType;
11507-
11508-
let addPositionalOnly = true;
11509-
11510-
const paramAnnotationOptions: AnnotationTypeOptions = {
11511-
allowParamSpec: true,
11512-
allowTypeVarTuple: true,
11513-
};
11514-
11515-
if ((flags & EvaluatorFlags.AssociateTypeVarsWithCurrentScope) !== 0) {
11516-
paramAnnotationOptions.associateTypeVarsWithScope = true;
11517-
}
11518-
11519-
node.parameters.forEach((param, paramIndex) => {
11520-
const paramType = getTypeOfAnnotation(param.typeAnnotation, paramAnnotationOptions);
11521-
11522-
if (isEllipsisType(paramType)) {
11523-
if (param.category !== ParameterCategory.Simple || paramIndex !== 0 || node.parameters.length > 1) {
11524-
addError(Localizer.Diagnostic.ellipsisContext(), param.typeAnnotation);
11525-
FunctionType.addParameter(functionType, {
11526-
category: ParameterCategory.Simple,
11527-
name: `__p${paramIndex}`,
11528-
isNameSynthesized: true,
11529-
type: UnknownType.create(),
11530-
hasDeclaredType: true,
11531-
});
11532-
} else {
11533-
functionType.details.flags |= FunctionTypeFlags.SkipArgsKwargsCompatibilityCheck;
11534-
FunctionType.addDefaultParameters(functionType);
11535-
addPositionalOnly = false;
11536-
}
11537-
} else if (param.category === ParameterCategory.Simple) {
11538-
if (isTypeVar(paramType) && paramType.details.isParamSpec) {
11539-
addError(Localizer.Diagnostic.arrowCallableParamSpec(), param.typeAnnotation);
11540-
}
11541-
11542-
if (isTypeVar(paramType) && paramType.details.isVariadic && !paramType.isVariadicUnpacked) {
11543-
addError(Localizer.Diagnostic.arrowCallableVariadicTypeVar(), param.typeAnnotation);
11544-
}
11545-
11546-
FunctionType.addParameter(functionType, {
11547-
category: ParameterCategory.Simple,
11548-
name: `__p${paramIndex}`,
11549-
isNameSynthesized: true,
11550-
type: convertToInstance(paramType),
11551-
hasDeclaredType: true,
11552-
});
11553-
} else if (param.category === ParameterCategory.VarArgList) {
11554-
if (!isVariadicTypeVar(paramType)) {
11555-
addError(Localizer.Diagnostic.arrowCallableNotVariadicTypeVar(), param.typeAnnotation);
11556-
} else {
11557-
if (paramType.isVariadicUnpacked) {
11558-
addError(Localizer.Diagnostic.arrowCallableVariadicTypeVarUnpacked(), param.typeAnnotation);
11559-
}
11560-
11561-
FunctionType.addParameter(functionType, {
11562-
category: ParameterCategory.Simple,
11563-
name: `__p${paramIndex}`,
11564-
isNameSynthesized: true,
11565-
type: convertToInstance(TypeVarType.cloneForUnpacked(paramType)),
11566-
hasDeclaredType: true,
11567-
});
11568-
}
11569-
} else if (param.category === ParameterCategory.VarArgDictionary) {
11570-
if (!isParamSpec(paramType)) {
11571-
addError(Localizer.Diagnostic.arrowCallableNotParamSpec(), param.typeAnnotation);
11572-
} else if (paramIndex !== node.parameters.length - 1) {
11573-
addError(Localizer.Diagnostic.arrowCallableParamSpecNotLast(), param.typeAnnotation);
11574-
} else {
11575-
functionType.details.paramSpec = paramType;
11576-
}
11577-
}
11578-
});
11579-
11580-
if (addPositionalOnly) {
11581-
FunctionType.addParameter(functionType, {
11582-
category: ParameterCategory.Simple,
11583-
type: UnknownType.create(),
11584-
});
11585-
}
11586-
11587-
return { node, type: functionType, isIncomplete };
11588-
}
11589-
1159011454
function getTypeFromDictionary(node: DictionaryNode, expectedType: Type | undefined): TypeResult {
1159111455
// If the expected type is a union, analyze for each of the subtypes
1159211456
// to find one that matches.
@@ -16421,8 +16285,7 @@ export function createTypeEvaluator(importLookup: ImportLookup, evaluatorOptions
1642116285
node.nodeType === ParseNodeType.PatternMapping ||
1642216286
node.nodeType === ParseNodeType.PatternValue ||
1642316287
node.nodeType === ParseNodeType.PatternMappingKeyEntry ||
16424-
node.nodeType === ParseNodeType.PatternMappingExpandEntry ||
16425-
node.nodeType === ParseNodeType.ArrowCallable
16288+
node.nodeType === ParseNodeType.PatternMappingExpandEntry
1642616289
);
1642716290
}
1642816291

packages/pyright-internal/src/localization/localize.ts

-9
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,6 @@ export namespace Localizer {
207207
export const argPositionalExpectedOne = () => getRawString('Diagnostic.argPositionalExpectedOne');
208208
export const argTypePartiallyUnknown = () => getRawString('Diagnostic.argTypePartiallyUnknown');
209209
export const argTypeUnknown = () => getRawString('Diagnostic.argTypeUnknown');
210-
export const arrowCallableIllegal = () => getRawString('Diagnostic.arrowCallableIllegal');
211-
export const arrowCallableNeedsParen = () => getRawString('Diagnostic.arrowCallableNeedsParen');
212-
export const arrowCallableNotParamSpec = () => getRawString('Diagnostic.arrowCallableNotParamSpec');
213-
export const arrowCallableNotVariadicTypeVar = () => getRawString('Diagnostic.arrowCallableNotVariadicTypeVar');
214-
export const arrowCallableParamSpec = () => getRawString('Diagnostic.arrowCallableParamSpec');
215-
export const arrowCallableParamSpecNotLast = () => getRawString('Diagnostic.arrowCallableParamSpecNotLast');
216-
export const arrowCallableVariadicTypeVar = () => getRawString('Diagnostic.arrowCallableVariadicTypeVar');
217-
export const arrowCallableVariadicTypeVarUnpacked = () =>
218-
getRawString('Diagnostic.arrowCallableVariadicTypeVarUnpacked');
219210
export const assertAlwaysTrue = () => getRawString('Diagnostic.assertAlwaysTrue');
220211
export const assignmentExprContext = () => getRawString('Diagnostic.assignmentExprContext');
221212
export const assignmentExprComprehension = () =>

packages/pyright-internal/src/localization/package.nls.en-us.json

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@
1919
"argPositionalExpectedOne": "Expected 1 positional argument",
2020
"argTypePartiallyUnknown": "Argument type is partially unknown",
2121
"argTypeUnknown": "Argument type is unknown",
22-
"arrowCallableIllegal": "Callable syntax requires Python 3.11 or newer",
23-
"arrowCallableNeedsParen": "Callable expression requires parentheses when used in union or with other operators",
24-
"arrowCallableNotParamSpec": "Expected ParamSpec after \"**\"",
25-
"arrowCallableNotVariadicTypeVar": "Expected TypeVarTuple after \"*\"",
26-
"arrowCallableParamSpec": "Expected \"**\" before ParamSpec",
27-
"arrowCallableParamSpecNotLast": "ParamSpec must be the last parameter",
28-
"arrowCallableVariadicTypeVarUnpacked": "TypeVarTuple is already unpacked; \"*\" is redundant",
29-
"arrowCallableVariadicTypeVar": "Expected \"*\" before TypeVarTuple",
3022
"assertAlwaysTrue": "Assert expression always evaluates to true",
3123
"assignmentExprContext": "Assignment expression must be within module, function or lambda",
3224
"assignmentExprComprehension": "Assignment expression target \"{name}\" cannot use same name as comprehension for target",

packages/pyright-internal/src/parser/parseNodes.ts

+1-51
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export const enum ParseNodeType {
104104
PatternMappingExpandEntry,
105105
PatternValue,
106106
PatternClassArgument,
107-
ArrowCallable,
108107
}
109108

110109
export const enum ErrorExpressionCategory {
@@ -687,8 +686,7 @@ export type ExpressionNode =
687686
| ListNode
688687
| SetNode
689688
| DecoratorNode
690-
| FunctionAnnotationNode
691-
| ArrowCallableNode;
689+
| FunctionAnnotationNode;
692690

693691
export function isExpressionNode(node: ParseNode): node is ExpressionNode {
694692
switch (node.nodeType) {
@@ -720,7 +718,6 @@ export function isExpressionNode(node: ParseNode): node is ExpressionNode {
720718
case ParseNodeType.DictionaryExpandEntry:
721719
case ParseNodeType.List:
722720
case ParseNodeType.Set:
723-
case ParseNodeType.ArrowCallable:
724721
return true;
725722

726723
default:
@@ -2247,52 +2244,6 @@ export namespace PatternValueNode {
22472244
}
22482245
}
22492246

2250-
export interface ArrowCallableParameter {
2251-
category: ParameterCategory;
2252-
typeAnnotation: ExpressionNode;
2253-
starToken?: Token;
2254-
}
2255-
2256-
export interface ArrowCallableNode extends ParseNodeBase {
2257-
readonly nodeType: ParseNodeType.ArrowCallable;
2258-
isAsync?: boolean;
2259-
parameters: ArrowCallableParameter[];
2260-
returnTypeAnnotation: ExpressionNode;
2261-
}
2262-
2263-
export namespace ArrowCallableNode {
2264-
export function create(
2265-
openParenToken: Token,
2266-
parameters: ArrowCallableParameter[],
2267-
returnTypeAnnotation: ExpressionNode,
2268-
asyncToken?: Token
2269-
) {
2270-
const node: ArrowCallableNode = {
2271-
start: openParenToken.start,
2272-
length: openParenToken.length,
2273-
nodeType: ParseNodeType.ArrowCallable,
2274-
id: _nextNodeId++,
2275-
parameters,
2276-
returnTypeAnnotation,
2277-
};
2278-
2279-
if (asyncToken) {
2280-
node.isAsync = true;
2281-
extendRange(node, asyncToken);
2282-
}
2283-
2284-
extendRange(node, returnTypeAnnotation);
2285-
2286-
parameters.forEach((expr) => {
2287-
expr.typeAnnotation.parent = node;
2288-
});
2289-
2290-
returnTypeAnnotation.parent = node;
2291-
2292-
return node;
2293-
}
2294-
}
2295-
22962247
export type PatternAtomNode =
22972248
| PatternSequenceNode
22982249
| PatternLiteralNode
@@ -2306,7 +2257,6 @@ export type PatternAtomNode =
23062257
export type ParseNode =
23072258
| ErrorNode
23082259
| ArgumentNode
2309-
| ArrowCallableNode
23102260
| AssertNode
23112261
| AssignmentExpressionNode
23122262
| AssignmentNode

0 commit comments

Comments
 (0)