Skip to content

Commit

Permalink
fix: Fix getting params defaults on Python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Feb 5, 2022
1 parent fd432dc commit 0afd867
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/griffe/agents/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,8 @@ def get_parameter_default(node: AST, filepath: Path, lines_collection: LinesColl
return None
if isinstance(node, NodeConstant):
return repr(node.value)
if isinstance(node, NodeStr):
return repr(node.s)
if isinstance(node, NodeName):
return node.id
if node.lineno == node.end_lineno: # type: ignore[attr-defined]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
from tests.helpers import temporary_visited_module


def test_visit_simple_function():
"""Test functions parameters loading."""
with temporary_visited_module("def f(foo='<>'): ...") as module:
function = module["f"]
assert len(function.parameters) == 1
param = function.parameters[0]
assert param is function.parameters["foo"]
assert param.name == "foo"
assert param.kind is ParameterKind.positional_or_keyword
assert param.default == "'<>'"


@pytest.mark.skipif(sys.version_info < (3, 8), reason="posonly syntax not supported on Python 3.7")
def test_visit_function_positional_only_param():
"""Test functions parameters loading."""
Expand Down

0 comments on commit 0afd867

Please sign in to comment.