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

Auto-detect user-written methods #324

Closed
hynek opened this issue Jan 16, 2018 · 5 comments
Closed

Auto-detect user-written methods #324

hynek opened this issue Jan 16, 2018 · 5 comments
Labels

Comments

@hynek
Copy link
Member

hynek commented Jan 16, 2018

Currently, if you want to implement a method yourself, you have to remember to do two things:

@attr.s(repr=False)
class C:
    def __repr__(self):
        return "whatever"

I’ve seen quite a few people be confused/frustrated by that.


I think unless these is set, it would be kind of cool if we detected that the current class (and not some super class) has a user-written method and set the flag to false automatically such that

@attr.s
class C:
    def __repr__(self):
        return "whatever"

does what you’d expect.

Opinions?

@hynek hynek added the Feature label Jan 16, 2018
@Tinche
Copy link
Member

Tinche commented Jan 16, 2018

👍

@euresti
Copy link
Contributor

euresti commented Jan 16, 2018

Same with __init__? (I ask because the mypy plugin will have to deal with that too.)

@hynek
Copy link
Member Author

hynek commented Jan 16, 2018

The idea is to support it for all of them. It gets a bit hairy when we get to comparison because it’s several ones. Would we stop completely? Or just not replace one of them?

@wsanchez
Copy link

With comparison methods, perhaps total_ordering could provide guidance; if you provide enough for total_ordering to work, we apply it or do something similar?

It's a bit of feature creep, but it feels in line with the developer doing as little work related to attributes as necessary and we take care of the rest.

@hynek
Copy link
Member Author

hynek commented Jan 16, 2018

The more I think about it the more I think we should just skip methods that have been defined and be done with it. That allows people to customise their classes even better.

hynek added a commit that referenced this issue Jan 6, 2020
hynek added a commit that referenced this issue Jan 6, 2020
hynek added a commit that referenced this issue Feb 8, 2020
hynek added a commit that referenced this issue Feb 10, 2020
hynek added a commit that referenced this issue Mar 7, 2020
hynek added a commit that referenced this issue Mar 8, 2020
hynek added a commit that referenced this issue Mar 13, 2020
hynek added a commit that referenced this issue Mar 13, 2020
@hynek hynek closed this as completed in 196d948 Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants