Skip to content

Improve docs of attr.s(match_args=True) #919

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

Merged
merged 3 commits into from
Feb 2, 2022
Merged

Conversation

sobolevn
Copy link
Contributor

@sobolevn sobolevn commented Feb 2, 2022

Summary

Hi!

I am implementing match_args support in Mypy and while reading your docs I was confused: how can attr.s work with positional-only arguments to __init__?

By positional-only many python devs mean this: def some(x, y, /): ...
But, this is not the case for attr.s, proof:

import attr

@attr.s(match_args=True, auto_attribs=True)
class ToMatch:
    x: int
    y: int
    z: int = attr.field(kw_only=True)

print(ToMatch(1, 2, z=3).__match_args__)  # ('x', 'y')
print(ToMatch(x=1, y=2, z=3).__match_args__)  # ('x', 'y')

As you see, here both x and y are regular arguments, they can be passed by position or by name.

So, I hope that the proposed wording will be cleaner! 👍

@hynek
Copy link
Member

hynek commented Feb 2, 2022

Oh yeah, I think what it means is "non-keyword-only"? I think that should be the phrasing.

Also lol @ this PR appearing literally minutes after me pushing a post1 with doc updates. 😅

@sobolevn
Copy link
Contributor Author

sobolevn commented Feb 2, 2022

I think what it means is "non-keyword-only"?

Good one, updating! 👍

Btw, my Mypy PR I was talking about (if you are intersted!): python/mypy#12111

@hynek
Copy link
Member

hynek commented Feb 2, 2022

Btw, my Mypy PR I was talking about (if you are intersted!): python/mypy#12111

Thanks for working on this!

I get dizzy when looking at Mypy code myself, but I see you've already roped in @Tinche so I'm sure it's in good hands. :)

@hynek hynek enabled auto-merge (squash) February 2, 2022 09:04
@hynek hynek merged commit a080e54 into python-attrs:main Feb 2, 2022
@sobolevn
Copy link
Contributor Author

sobolevn commented Feb 2, 2022

Thank you 🎉

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

Successfully merging this pull request may close these issues.

2 participants