Skip to content

Implement by_name #86

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 6 commits into from
Sep 10, 2016
Merged

Implement by_name #86

merged 6 commits into from
Sep 10, 2016

Conversation

hynek
Copy link
Member

@hynek hynek commented Sep 10, 2016

As a replacement for C.attribute that doesn't work with slots and is
overall bad design.

I’ve also improved the overall exception situation (and its documentation). Comments anyone?

@hynek hynek added this to the 16.2.0 milestone Sep 10, 2016
@codecov-io
Copy link

codecov-io commented Sep 10, 2016

Current coverage is 100% (diff: 100%)

Merging #86 into master will not change coverage

@@           master   #86   diff @@
===================================
  Files           8     8          
  Lines         443   446     +3   
  Methods         0     0          
  Messages        0     0          
  Branches       98    97     -1   
===================================
+ Hits          443   446     +3   
  Misses          0     0          
  Partials        0     0          

Powered by Codecov. Last update 024a16c...b6476fb

@hynek
Copy link
Member Author

hynek commented Sep 10, 2016

This sort-of fixes #82.

@Tinche
Copy link
Member

Tinche commented Sep 10, 2016

A thought. What about instead of attrs_attrs being a tuple of Attributes, we make it an ordered dictionary of attribute names to attributes?

It's an internal thing, and fields() can be changed to just return list(attrs_attrs.values()) or something.

@Tinche
Copy link
Member

Tinche commented Sep 10, 2016

Or, since I'm brainstorming, a namedtuple. That might even give us a prettier API than the dict-like by_name.

@Tinche
Copy link
Member

Tinche commented Sep 10, 2016

If it's a namedtuple, you could do both:

for a in fields(C):
    pass

and

my_attr = fields(C).my_attr

(Again, just brainstorming, it's too early for me :p)

@hynek
Copy link
Member Author

hynek commented Sep 10, 2016

I kind of forgot, that the whole point of fields() is to enable us to do such changes. :D

The irony of using namedtuples within attrs is left to the reader.

@Tinche
Copy link
Member

Tinche commented Sep 10, 2016

The thought of using an attrs slot class here did cross my mind, but I was afraid of attrs-ception.

However, namedtuples can't have fields beginning with underscore, and we obviously support attributes with names beginning with underscore. This limitation is probably so you can't clash with a method name, like _asdict, _make or _replace. We are of course better than namedtuple and don't make our users deal with this crap.

I like the API a lot, so let me play around with it, implement it another way.

As a replacement for C.attribute that doesn't work with __slots__ and is
overall bad design.
@hynek
Copy link
Member Author

hynek commented Sep 10, 2016

OK the new API is

cr58n9nwiaapzm0

@hynek hynek merged commit adfdbf9 into master Sep 10, 2016
@hynek hynek deleted the by_name branch September 10, 2016 17:14
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.

3 participants