Skip to content

Commit

Permalink
Add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Jun 27, 2023
1 parent e9a7fc8 commit fef38f2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion astroid/nodes/as_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def visit_nonlocal(self, node) -> str:

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

def visit_pass(self, node) -> str:
"""return an astroid.Pass node as string"""
Expand Down
29 changes: 28 additions & 1 deletion tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
transforms,
util,
)
from astroid.const import PY310_PLUS, Context
from astroid.const import PY310_PLUS, PY312_PLUS, Context
from astroid.context import InferenceContext
from astroid.exceptions import (
AstroidBuildingError,
Expand Down Expand Up @@ -279,6 +279,33 @@ def test_as_string_unknown() -> None:
assert nodes.Unknown(lineno=1, col_offset=0).as_string() == "Unknown.Unknown()"


@pytest.mark.skipif(not PY312_PLUS, reason="Uses 3.12 type param nodes")
class AsStringTypeParamNodes(unittest.TestCase):
@staticmethod
def test_as_string_type_alias() -> None:
ast = abuilder.string_build("type Point = tuple[float, float]")
type_alias = ast.body[0]
assert type_alias.as_string().strip() == "Point"

@staticmethod
def test_as_string_type_var() -> None:
ast = abuilder.string_build("type Point[T] = tuple[float, float]")
type_var = ast.body[0].type_params[0]
assert type_var.as_string().strip() == "T"

@staticmethod
def test_as_string_type_var_tuple() -> None:
ast = abuilder.string_build("type Alias[*Ts] = tuple[*Ts]")
type_var_tuple = ast.body[0].type_params[0]
assert type_var_tuple.as_string().strip() == "*Ts"

@staticmethod
def test_as_string_param_spec() -> None:
ast = abuilder.string_build("type Alias[**P] = Callable[P, int]")
param_spec = ast.body[0].type_params[0]
assert param_spec.as_string().strip() == "P"


class _NodeTest(unittest.TestCase):
"""Test transformation of If Node."""

Expand Down

0 comments on commit fef38f2

Please sign in to comment.