mirror of
https://github.com/microsoft/pyright.git
synced 2025-12-23 09:19:29 +00:00
Fixed bug that results in a false positive error when a with statement has a single parenthesized context manager. This addresses #11020. (#11024)
Some checks failed
Run mypy_primer on push / Run mypy_primer on push (push) Has been cancelled
Validation / Typecheck (push) Has been cancelled
Validation / Style (push) Has been cancelled
Validation / Test macos-latest (push) Has been cancelled
Validation / Test ubuntu-latest (push) Has been cancelled
Validation / Test windows-latest (push) Has been cancelled
Validation / Build (push) Has been cancelled
Validation / Required (push) Has been cancelled
Some checks failed
Run mypy_primer on push / Run mypy_primer on push (push) Has been cancelled
Validation / Typecheck (push) Has been cancelled
Validation / Style (push) Has been cancelled
Validation / Test macos-latest (push) Has been cancelled
Validation / Test ubuntu-latest (push) Has been cancelled
Validation / Test windows-latest (push) Has been cancelled
Validation / Build (push) Has been cancelled
Validation / Required (push) Has been cancelled
This commit is contained in:
parent
346f74cb92
commit
b1c9ae2bb8
1 changed files with 8 additions and 2 deletions
|
|
@ -2317,6 +2317,8 @@ export class Parser {
|
|||
// "dry run" to determine whether the entire list of "with items"
|
||||
// is enclosed in parentheses.
|
||||
let isParenthesizedWithItemList = false;
|
||||
let isParenthesizedDisallowed = false;
|
||||
|
||||
if (possibleParen.type === TokenType.OpenParenthesis) {
|
||||
const openParenTokenIndex = this._tokenIndex;
|
||||
|
||||
|
|
@ -2337,7 +2339,11 @@ export class Parser {
|
|||
this._peekToken().type === TokenType.CloseParenthesis &&
|
||||
this._peekToken(1).type === TokenType.Colon
|
||||
) {
|
||||
isParenthesizedWithItemList = withItemList.length !== 1 || withItemList[0].d.target !== undefined;
|
||||
isParenthesizedWithItemList = true;
|
||||
|
||||
// Some forms of parenthesized context with statements were not
|
||||
// allowed prior to Python 3.9. Is this such a form?
|
||||
isParenthesizedDisallowed = withItemList.length !== 1 || withItemList[0].d.target !== undefined;
|
||||
}
|
||||
|
||||
this._tokenIndex = openParenTokenIndex;
|
||||
|
|
@ -2347,7 +2353,7 @@ export class Parser {
|
|||
|
||||
if (isParenthesizedWithItemList) {
|
||||
this._consumeTokenIfType(TokenType.OpenParenthesis);
|
||||
if (PythonVersion.isLessThan(this._getLanguageVersion(), pythonVersion3_9)) {
|
||||
if (isParenthesizedDisallowed && PythonVersion.isLessThan(this._getLanguageVersion(), pythonVersion3_9)) {
|
||||
this._addSyntaxError(LocMessage.parenthesizedContextManagerIllegal(), possibleParen);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue