forked from pylint-dev/astroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TypeAlias and TypeVar nodes (Python 3.12)
- Loading branch information
1 parent
d1ef13e
commit 38fa8e9
Showing
7 changed files
with
195 additions
and
4 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
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
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,31 @@ | ||
# 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 | ||
|
||
import pytest | ||
|
||
from astroid import extract_node | ||
from astroid.const import PY312_PLUS | ||
from astroid.nodes import Subscript, TypeAlias, TypeVar | ||
|
||
|
||
@pytest.mark.skipif(not PY312_PLUS, reason="Requires Python 3.12 or higher") | ||
def test_type_alias() -> None: | ||
node = extract_node("type Point[T] = list[float, float]") | ||
assert isinstance(node, TypeAlias) | ||
assert isinstance(node.type_params[0], TypeVar) | ||
assert node.type_params[0].name == "T" | ||
assert node.type_params[0].bound is None | ||
|
||
assert isinstance(node.value, Subscript) | ||
assert node.value.value.name == "list" | ||
assert node.value.slice.name == "tuple" | ||
assert all(elt.name == "float" for elt in node.value.slice.elts) | ||
|
||
|
||
@pytest.mark.skipif(not PY312_PLUS, reason="Requires Python 3.12 or higher") | ||
def test_type_param() -> None: | ||
node = extract_node("def func[T]() -> T: ...") | ||
assert isinstance(node.type_params[0], TypeVar) | ||
assert node.type_params[0].name == "T" | ||
assert node.type_params[0].bound is None |