Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agent/nodes.py cannot parse f-string when it's numeric #80

Closed
nicolefinnie opened this issue Jun 1, 2022 · 5 comments
Closed

agent/nodes.py cannot parse f-string when it's numeric #80

nicolefinnie opened this issue Jun 1, 2022 · 5 comments

Comments

@nicolefinnie
Copy link

Describe the bug

When pyupgrade automatically upgrades our formatted string to a f-string, griffe.agents.nodes.py cannot parse the f-string and throws an error

  File "/home/nicolefinnie/venv/myproject/lib/python3.8/site-packages/griffe/agents/nodes.py", line 764, in _get_call_value
    posargs = ", ".join(get_value(arg) for arg in node.args)

To Reproduce

Run mkdocs serve for this code snippet

key = 0.02
a = f"{round(key, 2)}"

Expected behavior
no error should be thrown and _get_call_value() should be able to accept a numeric value.

System (please complete the following information):

  • griffe version: 0.14.0
  • Python version: 3.8.5
  • OS: Ubuntu 20.4 LTS

Suggested fix

casting the value to str in the file agents/nodes.py, line 764, however, I am not sure about the side effect, which has to be validated through the CI/CD pipeline.

def _get_call_value(node: NodeCall) -> str:
    # cast get_value() to string
    posargs = ", ".join(str(get_value(arg)) for arg in node.args)
    kwargs = ", ".join(get_value(kwarg) for kwarg in node.keywords)
    if posargs and kwargs:
        args = f"{posargs}, {kwargs}"
    elif posargs:
        args = posargs
    elif kwargs:
        args = kwargs
    else:
        args = ""
    return f"{get_value(node.func)}({args})"
@pawamoy
Copy link
Member

pawamoy commented Jun 1, 2022

I suppose you're getting a KeyError? Could you tell me which one it is exactly ^^? Or provide the full traceback? Thanks

@nicolefinnie
Copy link
Author

I suppose you're getting a KeyError? Could you tell me which one it is exactly ^^? Or provide the full traceback? Thanks

Thanks for the quick response. The error is in the original post, here is the full traceback.

griffe_issue_80.log

pawamoy added a commit that referenced this issue Jun 3, 2022
@pawamoy
Copy link
Member

pawamoy commented Jun 3, 2022

Thanks, should be fixed now, in 0.20.0 🙂

@pawamoy pawamoy closed this as completed Jun 3, 2022
@nicolefinnie
Copy link
Author

Thanks, should be fixed now, in 0.20.0 slightly_smiling_face

Awesome thanks!

@wsascha
Copy link

wsascha commented Jun 4, 2022

Wow, that was fast! Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants