-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix a crash when inferring a
typing.TypeVar
call. (#2239)
Closes pylint-dev/pylint#8802
- Loading branch information
Showing
3 changed files
with
45 additions
and
3 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,24 @@ | ||
# 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" |