|
28 | 28 | transforms,
|
29 | 29 | util,
|
30 | 30 | )
|
31 |
| -from astroid.const import PY310_PLUS, Context |
| 31 | +from astroid.const import PY310_PLUS, PY312_PLUS, Context |
32 | 32 | from astroid.context import InferenceContext
|
33 | 33 | from astroid.exceptions import (
|
34 | 34 | AstroidBuildingError,
|
@@ -279,6 +279,33 @@ def test_as_string_unknown() -> None:
|
279 | 279 | assert nodes.Unknown(lineno=1, col_offset=0).as_string() == "Unknown.Unknown()"
|
280 | 280 |
|
281 | 281 |
|
| 282 | +@pytest.mark.skipif(not PY312_PLUS, reason="Uses 3.12 type param nodes") |
| 283 | +class AsStringTypeParamNodes(unittest.TestCase): |
| 284 | + @staticmethod |
| 285 | + def test_as_string_type_alias() -> None: |
| 286 | + ast = abuilder.string_build("type Point = tuple[float, float]") |
| 287 | + type_alias = ast.body[0] |
| 288 | + assert type_alias.as_string().strip() == "Point" |
| 289 | + |
| 290 | + @staticmethod |
| 291 | + def test_as_string_type_var() -> None: |
| 292 | + ast = abuilder.string_build("type Point[T] = tuple[float, float]") |
| 293 | + type_var = ast.body[0].type_params[0] |
| 294 | + assert type_var.as_string().strip() == "T" |
| 295 | + |
| 296 | + @staticmethod |
| 297 | + def test_as_string_type_var_tuple() -> None: |
| 298 | + ast = abuilder.string_build("type Alias[*Ts] = tuple[*Ts]") |
| 299 | + type_var_tuple = ast.body[0].type_params[0] |
| 300 | + assert type_var_tuple.as_string().strip() == "*Ts" |
| 301 | + |
| 302 | + @staticmethod |
| 303 | + def test_as_string_param_spec() -> None: |
| 304 | + ast = abuilder.string_build("type Alias[**P] = Callable[P, int]") |
| 305 | + param_spec = ast.body[0].type_params[0] |
| 306 | + assert param_spec.as_string().strip() == "P" |
| 307 | + |
| 308 | + |
282 | 309 | class _NodeTest(unittest.TestCase):
|
283 | 310 | """Test transformation of If Node."""
|
284 | 311 |
|
|
0 commit comments