-
-
Notifications
You must be signed in to change notification settings - Fork 374
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
__attrs_init__() #731
__attrs_init__() #731
Conversation
This comment has been minimized.
This comment has been minimized.
6a68a6f
to
9030d1e
Compare
First an important lifehack: the solution to your As for the PR: it is quite intrusive, are you sure you wouldn't be fine with |
I'm fine with Note, however, that this PR does maintain the types for |
Your impression is 100% on point! It's just that we need both anyways and
Maybe I misunderstand, but the point of IOW instead of: @attr.define
class C:
x: int
def __attrs_pre_init__(self):
do_a()
def __attrs_post_init__(self):
do_b() The user can write: @attr.define(init=some_magic_value_we_need_to_agree_on)
class C:
x: int
def __init__(self, x: int) -> None:
do_a()
self.__attrs_init__()
do_b() Are we on the same page at all or am I being confusing? |
As I understand it now, your idea is: based on the I was doing something slightly different: always providing an Separately:
Conversely, why add
|
This is now ready for review. |
@hynek just want to check that this is on your radar. no rush but if you happen to know when you might get to it, i won't bug you until then :) |
Yes it is, sorry. I need to get out a structlog release before I can focus on bigger attrs work. |
ping? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delays and thank you for your patience! Overall this is all high quality, but we need to figure out some edge cases together.
Co-authored-by: Hynek Schlawack <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool,thanks! This is an exciting feature!
We should add some docs to init.rst but that doesn't need to happen here.
So, since you're knee deep in this code: do you think it would be feasible to also add I still think that's more useful for most people, that just want to call |
Signed-off-by: Hynek Schlawack <[email protected]>
Here's a first pass for #725. @hynek, please take a look to see if you like this approach, and I can then do all the polish work below. Tests were passing at least locally, for py38.
Please ignore all thepoetry
-related noise, I'll get rid of that.It's a bit ugly for a few reasons:
I wanted to have
{args}
in both the auto-generated__init__
and__attrs_init__
, but didn't want to repeat or call that code twice; and it seems non-trival to factor out.We have to always generate
__attrs_init__
(so that the user-provided__init__
can refer to it), but conditionally generate__init__
as before.Because of (2),
Factory
now calls_make_init
(even though it has defined__init__
), but_make_init
refers toFactory
, so we need a small hack for this.I think that
__attrs_pre_init__
will be cleaner to implement, and I'm not sure I fully see the advantages of__attrs_init__
over__attrs_pre_init__
. Thoughts?Pull Request Check List
This is just a friendly reminder about the most common mistakes. Please make sure that you tick all boxes. But please read our contribution guide at least once, it will save you unnecessary review cycles!
If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing left to do. If your pull request is a documentation fix or a trivial typo, feel free to delete the whole thing.
.pyi
).tests/typing_example.py
.docs/api.rst
by hand.@attr.s()
have to be added by hand too.versionadded
,versionchanged
, ordeprecated
directives. Find the appropriate next version in our__init__.py
file..rst
files is written using semantic newlines.changelog.d
.If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!