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

Add attr.define/mutable/frozen #666

Merged
merged 11 commits into from
Aug 17, 2020
Merged

Add attr.define/mutable/frozen #666

merged 11 commits into from
Aug 17, 2020

Conversation

hynek
Copy link
Member

@hynek hynek commented Aug 14, 2020

Prepare for import attrs y'all!

This is basically what we kinda agreed on in #408 and #487.

I'm open to comments and suggestions.

Also suggestions how to supply type stubs without a major copy/paste operation. 😳

Prepare for import attrs y'all!

Signed-off-by: Hynek Schlawack <[email protected]>
@lig
Copy link

lig commented Aug 14, 2020

My wishes:

  • kw_only by default
  • auto_attribs by default
  • attrs.Field() for attributes
  • attrs.Class() for class decorators
  • allow to inherit something like attrs.BaseClass to be able to use isinstance(obj, attrs.BaseClass) later (basically allow to detect that we have attrs class)
  • recursive attrs.from_dict()
  • transparent builder API to simplify third party tools integration like converters between ORM models and attrs, serializer, etc
  • regarding defaults, maybe allow building your own factory which provides required defaults to reuse it later.

@hynek
Copy link
Member Author

hynek commented Aug 14, 2020

To be clear, I'm only looking for stuff that we might paint ourselves into the corner. Most of what you listed can be fixed at any time.

@hynek hynek changed the title Add attr.auto/mutable/frozen Add attr.define/mutable/frozen Aug 14, 2020
hynek added 2 commits August 14, 2020 17:21
This is going be the next-gen name anyways, so no need to introduce new names.

Signed-off-by: Hynek Schlawack <[email protected]>
@lig
Copy link

lig commented Aug 14, 2020

  • kw_only=True is not happening, because I had it in characteristic and people (including myself) hated it.

:( it is how it is then. anyway, everybody needs different defaults

  • not sure what you mean? Just a different name? I'm indeed thinking to go for attrs.field or attrs.Field in the next APIs.

well, kinda. if it will be import attrs then attrs.ib doesn't work anymore. So, if import attr works as before then new API with import attrs needs something new and explicit.

Doesn't matter much, define works as well. attrs.s looks kinda "meh"

  • uh, attr.has?

Nice. Never noticed it. Maybe, missed in the docs and then didn't recognize it with autocomplete. The name feels a bot misleading to guess what it does straight away. Thanks for educating me on this:)

Well, maybe the next point will help with it. However, it feels like it's not that complex and it would fully complement asdict. It's your call, no pressure here. cattrs worked for me.

  • that's interesting but out of scope for this issue

Fair enough. Shall I describe the idea in a separate issue?

Making this work with fewer tricks would help. Docs are good, though:)

Thanks and keep up the good work!

@hynek
Copy link
Member Author

hynek commented Aug 14, 2020

  • not sure what you mean? Just a different name? I'm indeed thinking to go for attrs.field or attrs.Field in the next APIs.

well, kinda. if it will be import attrs then attrs.ib doesn't work anymore. So, if import attr works as before then new API with import attrs needs something new and explicit.

Yeah, it's prob gonna be attrs.field.

  • that's interesting but out of scope for this issue

Fair enough. Shall I describe the idea in a separate issue?

Sure!

Thanks and keep up the good work!

💛

@euresti
Copy link
Contributor

euresti commented Aug 14, 2020

This is neat. I will have to spend some time fixing the mypy plugin to get these to work.

@hynek
Copy link
Member Author

hynek commented Aug 17, 2020

This is neat.

Not sure if sarcasm. ;)

I will have to spend some time fixing the mypy plugin to get these to work.

Do the annotations look OK so far? I don't think I can do anymore than release and wait for mypy, correct?

src/attr/_next_gen.py Show resolved Hide resolved
src/attr/__init__.pyi Outdated Show resolved Hide resolved
@euresti
Copy link
Contributor

euresti commented Aug 17, 2020

Not sarcasm, I'm excited to not have to confuse people in my team with @dataclass (no, not that kind of dataclass)

@hynek
Copy link
Member Author

hynek commented Aug 17, 2020

I guess there's no point in procrastinating on this any further…merging and if nobody yells at me, I'll release 20.1 tomorrow.

@hynek hynek merged commit b02335f into master Aug 17, 2020
@hynek hynek deleted the auto branch August 17, 2020 14:22
hynek added a commit that referenced this pull request Aug 20, 2020
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.

4 participants