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

Positional-only arguments are mishandled in signatures #25

Closed
FasterSpeeding opened this issue Jun 12, 2022 · 1 comment
Closed

Positional-only arguments are mishandled in signatures #25

FasterSpeeding opened this issue Jun 12, 2022 · 1 comment

Comments

@FasterSpeeding
Copy link
Contributor

FasterSpeeding commented Jun 12, 2022

Describe the bug
Positional-only arguments are mishandled in signatures with / always being put at the start of a signature with positional-only arguments regardless of how many arguments are positional only.

To Reproduce
With the following test code being targeted by mkdocstrings

# test.py
def bar(foo: str, baz: int, /, *, bar: int = 123) -> None:
    """meow"""

and the following mkdocs.yml

# mkdocs.yml
site_name: "Docs"
plugins:
  - search
  - mkdocstrings:
      default_handler: python
      watch:
        - test.py

build documentation from this module and watch it place / at the start of bar's signature as shown in the following screenshot.

Expected behavior
/ should appear after baz in the signature.

Screenshots

image

System (please complete the following information):

  • mkdocstrings-python version: 0.7.0
  • mkdocstrings version: 0.19.0
  • griffe version: 0.20.0
  • mkdocs version: 1.3.0
  • Python version: 3.10
  • OS: Windows

Additional context
This leads to an error being raised in cases where black is used to reformat function signatures with positional only arguments as / cannot be the first argument of a function syntax wise.

I can't really read this code but from what I can tell the responsible code might be here

{%- if parameter.kind.value == "positional-only" -%}
{%- if ns.render_pos_only_separator -%}
{%- set ns.render_pos_only_separator = False %}/, {% endif -%}
(where it's adding in / the moment it finds a positional only argument that isn't named self or cls rather than waiting until it reaches the end of the positional only arguments). I did try griffe with the example code and it seemed to be handling positional-only arguments properly.

pawamoy added a commit that referenced this issue Jun 12, 2022
Previously, `/` was added in front of positional-only
parameters. It is now fixed: `/` is added at the end
of such parameters.

Issue #25: #25
@pawamoy
Copy link
Member

pawamoy commented Jun 12, 2022

Hi, thank you so much for the very detailed report and investigation! This is greatly appreciated.

I was able to replicate with the example you provided 👍
This should be fixed in version 0.7.1 🙂
Closing! Let me know if something is wrong.

@pawamoy pawamoy closed this as completed Jun 12, 2022
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

2 participants