-
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport maintenance/2.15.x] Fix a crash when inferring a `typing.Ty…
…peVar` call. (#2254) * Fix a crash when inferring a `typing.TypeVar` call. (#2239) Closes pylint-dev/pylint#8802 (cherry picked from commit 89dfb48) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Mark Byrne <31762852+mbyrnepr2@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
30c3112
commit 28ef038
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html | ||
# For details: https://github.com/PyCQA/astroid/blob/main/LICENSE | ||
# Copyright (c) https://github.com/PyCQA/astroid/blob/main/CONTRIBUTORS.txt | ||
# Licensed under the LGPL: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html | ||
# For details: https://github.com/pylint-dev/astroid/blob/main/LICENSE | ||
# Copyright (c) https://github.com/pylint-dev/astroid/blob/main/CONTRIBUTORS.txt | ||
|
||
from astroid import builder, nodes | ||
|
||
|
||
def test_infer_typevar() -> None: | ||
""" | ||
Regression test for: https://github.com/pylint-dev/pylint/issues/8802 | ||
Test that an inferred `typing.TypeVar()` call produces a `nodes.ClassDef` | ||
node. | ||
""" | ||
assign_node = builder.extract_node( | ||
""" | ||
from typing import TypeVar | ||
MyType = TypeVar('My.Type') | ||
""" | ||
) | ||
call = assign_node.value | ||
inferred = next(call.infer()) | ||
assert isinstance(inferred, nodes.ClassDef) | ||
assert inferred.name == "My.Type" |