Skip to content

Commit fef38f2

Browse files
Add coverage
1 parent e9a7fc8 commit fef38f2

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

astroid/nodes/as_string.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ def visit_nonlocal(self, node) -> str:
435435

436436
def visit_paramspec(self, node: nodes.ParamSpec) -> str:
437437
"""return an astroid.ParamSpec node as string"""
438-
return node.name
438+
return node.name.accept(self)
439439

440440
def visit_pass(self, node) -> str:
441441
"""return an astroid.Pass node as string"""

tests/test_nodes.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
transforms,
2929
util,
3030
)
31-
from astroid.const import PY310_PLUS, Context
31+
from astroid.const import PY310_PLUS, PY312_PLUS, Context
3232
from astroid.context import InferenceContext
3333
from astroid.exceptions import (
3434
AstroidBuildingError,
@@ -279,6 +279,33 @@ def test_as_string_unknown() -> None:
279279
assert nodes.Unknown(lineno=1, col_offset=0).as_string() == "Unknown.Unknown()"
280280

281281

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+
282309
class _NodeTest(unittest.TestCase):
283310
"""Test transformation of If Node."""
284311

0 commit comments

Comments
 (0)