News for hackers. Stuff that matters.
Re:Using attrs for everything in Python by mixmastamyk on Thursday August 25, 2016 @12:53PM (#12360526)
Also, read the post and looked over the docs, and don't see any explanation of what `.s` and `.ib` is supposed to mean (though I can figure out from context). Does anyone know what the letters stand for? Struct and instance b…???
Re:Using attrs for everything in Python by Myrmornis on Thursday August 25, 2016 @01:04PM (#12360613)
> They are a concise and highly readable way to write attrs and attrib with an explicit namespace.

> For those who can’t swallow that API at all, attrs comes with serious business aliases: attr.attrs and attr.attrib.

I'm definitely in the can't swallow camp. There's no precedent for using attribute namespaces to name things with half the name on one side and half the name on the other side, so who the hell does this project think it is to start doing it? :) Seriously though I'm pretty sure I hate it.

And I'm having trouble liking the "proper" names. So we use a class decorator "@attrs" to declare "this class is going to use class attributes to declare available instance attributes slots, a bit like django or schematics fields". Maybe it would have been better to call it "@attrs.model" since it is essentially a model definition in the terminology of other data modeling projects?

Re:Using attrs for everything in Python by gknoy on Thursday August 25, 2016 @05:20PM (#12362601)
If you use `import ... as ...`, you can rename them to nicer names (full gist at [0]):

    from attr import (
        s as AttributedModel,
        ib as attribute,
    )
    
    @AttributedModel
    class Bar(object):
        x = attribute()
        y = attribute()


0: https://gist.github.com/gknoy/6e884fce3edda08a1566823fec37ba...
Re:Using attrs for everything in Python by jfb on Thursday August 25, 2016 @12:56PM (#12360555)
attr.s = "attrs" = plural of "attr"

attr.ib = "attirb" = alternate spelling of "attr"

It's too cute by half.

Re:Using attrs for everything in Python by ctoth on Thursday August 25, 2016 @07:04PM (#12363166)
It's awesome that Glyph wrote this article, but so many people are getting stuck on the default names here (me too, I don't like them so very much) that it's really detracting from the commentariet.

From the Attrs documentation:

(If you don’t like the playful attr.s and attr.ib, you can also use their no-nonsense aliases attr.attributes and attr.attr).

Re:Using attrs for everything in Python by hynek on Thursday August 25, 2016 @12:54PM (#12360537)