mirror of
https://github.com/microsoft/pyright.git
synced 2024-09-11 07:55:56 +03:00
Fixed bug that results in a false negative syntax error when a PEP-695 type alias uses a keyword as a name. This addresses #7933.
This commit is contained in:
parent
7ccf956b0f
commit
022b30a1f8
@ -146,7 +146,6 @@ import {
|
||||
StringTokenFlags,
|
||||
Token,
|
||||
TokenType,
|
||||
softKeywords,
|
||||
} from './tokenizerTypes';
|
||||
|
||||
interface ListResult<T> {
|
||||
@ -2967,7 +2966,10 @@ export class Parser {
|
||||
const peekToken2 = this._peekToken(2);
|
||||
let isInvalidTypeToken = true;
|
||||
|
||||
if (peekToken1.type === TokenType.Identifier || peekToken1.type === TokenType.Keyword) {
|
||||
if (
|
||||
peekToken1.type === TokenType.Identifier ||
|
||||
(peekToken1.type === TokenType.Keyword && KeywordToken.isSoftKeyword(peekToken1 as KeywordToken))
|
||||
) {
|
||||
if (peekToken2.type === TokenType.OpenBracket) {
|
||||
isInvalidTypeToken = false;
|
||||
} else if (
|
||||
@ -5087,8 +5089,8 @@ export class Parser {
|
||||
|
||||
// If this is a "soft keyword", it can be converted into an identifier.
|
||||
if (nextToken.type === TokenType.Keyword) {
|
||||
const keywordType = this._peekKeywordType();
|
||||
if (softKeywords.find((type) => type === keywordType)) {
|
||||
const keywordToken = nextToken as KeywordToken;
|
||||
if (KeywordToken.isSoftKeyword(keywordToken)) {
|
||||
const keywordText = this._fileContents!.substr(nextToken.start, nextToken.length);
|
||||
this._getNextToken();
|
||||
return IdentifierToken.create(nextToken.start, nextToken.length, keywordText, nextToken.comments);
|
||||
|
@ -319,6 +319,10 @@ export namespace KeywordToken {
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
export function isSoftKeyword(token: KeywordToken) {
|
||||
return softKeywords.some((t) => token.keywordType === t);
|
||||
}
|
||||
}
|
||||
|
||||
export interface StringToken extends Token {
|
||||
|
Loading…
Reference in New Issue
Block a user