Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python.announce > #2495
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Hynek Schlawack <hs@ox.cx> |
| Newsgroups | comp.lang.python.announce |
| Subject | attrs 17.1.0 |
| Date | Tue, 16 May 2017 20:23:31 +0200 |
| Lines | 133 |
| Approved | python-announce-list@python.org |
| Message-ID | <mailman.57.1494960044.30375.python-announce-list@python.org> (permalink) |
| References | <845C441B-10BA-43D4-8844-A11405480F74@ox.cx> |
| Mime-Version | 1.0 (Mac OS X Mail 10.3 \(3273\)) |
| Content-Type | multipart/signed; boundary="Apple-Mail=_0037E0C9-3BF9-4D02-B1FD-667B3E96648D"; protocol="application/pgp-signature"; micalg=pgp-sha256 |
| X-Trace | news.uni-berlin.de Odm9sq0kLfYZcPOd1+5PnwW2gXSgucC7JzVULiZNTniA== |
| Return-Path | <hs@ox.cx> |
| X-Original-To | python-announce-list@python.org |
| Delivered-To | python-announce-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'pycon': 0.04; 'defaults': 0.07; 'received:internal': 0.07; 'val': 0.07; 'dict': 0.09; 'filename:fname piece:signature': 0.09; 'logic': 0.09; 'mutable': 0.09; 'received:10.202': 0.09; 'received:10.202.2': 0.09; 'received:66.111': 0.09; 'received:66.111.4': 0.09; 'received:messagingengine.com': 0.09; 'valueerror:': 0.09; 'bug': 0.10; 'everyone,': 0.13; 'def': 0.13; 'explicitly': 0.15; '[1,': 0.16; 'attribute,': 0.16; 'attribute:': 0.16; 'attrs': 0.16; 'content-disposition:attachment;\r\n\tfilename=signature.asc': 0.16; 'content-type:application/pgp-signature': 0.16; 'content- type:multipart/signed': 0.16; 'enum': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'news:': 0.16; 'received:10.202.2.161': 0.16; 'syntactic': 0.16; 'attribute': 0.18; '>>>': 0.18; 'keys': 0.22; 'skip:` 10': 0.22; '(most': 0.24; 'import': 0.26; 'raise': 0.27; 'passing': 0.27; 'pass': 0.29; '2017,': 0.29; 'changes:': 0.29; 'implicitly': 0.29; 'preceding': 0.29; 'objects': 0.29; 'this.': 0.30; 'equal': 0.31; '(we': 0.32; 'smaller': 0.32; 'decorators': 0.33; 'instances': 0.33; 'traceback': 0.33; 'list': 0.33; 'url:en': 0.33; 'allows': 0.34; 'release': 0.34; 'but': 0.34; 'self': 0.35; 'class': 0.36; 'url:org': 0.36; 'handle': 0.37; 'method': 0.37; 'creation': 0.38; 'received:10': 0.38; 'bad': 0.38; 'lines': 0.38; 'to:addr:python.org': 0.39; 'received:io': 0.39; 'received:psf.io': 0.39; 'received:ams1.psf.io': 0.40; 'received:mail1.ams1.psf.io': 0.40; 'skip:n 20': 0.60; 'call': 0.61; 'header:Message-Id:1': 0.61; 'great': 0.62; 'skip:a 40': 0.67; 'therefore': 0.69; 'features:': 0.72; 'to:addr:python- announce-list': 0.72; 'led': 0.72; 'you:': 0.79; "'state'": 0.84; 'compose': 0.84; 'highlights:': 0.84; 'sets,': 0.84; 'you\xe2\x80\x99ll': 0.91; '***': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc :x-sasl-enc; s=fm1; bh=K7EjdhjjTJMRTrcloL5CZ+6O63hqROcVo1drS3UOg BA=; b=p1dl3KnXVuVHZo5SlbDHDD3rMZIvbmFSweQzCYIa4IYtl2gtLD38CsYhN CL2eMq60E4bn2HsosLL+pJIEbRLYU+0WEDZRRyCFmGTD4j/Si358gZazTdZMofLv /VF8BNDvM2zlxCDzCMg/p7nEwcOiZ+d8ircnchk8GBefyn0oZyfrWgEkhwm6nMI7 IaZ8tmNET9eoT6C3mdNltmJzj5cW4Tt/VmRih81Ynf1PhJ85wYpHNXvZrI7rd1f5 UUsh51BhpP8ZR8CXSOWwGc3fS8NGDOfqms1ommO3QHZD3+lrVjIg10WCvLPseb6Z WxrT6gIrgtFP6/ZSWBFvneVAZeMtA== |
| X-ME-Sender | <xms:pkMbWWZpkH51QIhi37IREfI9lSU-j3sQ0bVVrCQRCcaxBadF4Q6BCw> |
| X-Sasl-enc | GWHd6wQ63Fw/L4s4YMI76pAB7doEu4JN78kEopC6emle 1494959013 |
| X-Mailer | Apple Mail (2.3273) |
| X-Mailman-Approved-At | Tue, 16 May 2017 14:40:44 -0400 |
| X-BeenThere | python-announce-list@python.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Announcement-only list for the Python programming language <python-announce-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-announce-list/> |
| List-Post | <mailto:python-announce-list@python.org> |
| List-Help | <mailto:python-announce-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <845C441B-10BA-43D4-8844-A11405480F74@ox.cx> |
| Xref | csiph.com comp.lang.python.announce:2495 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi everyone,
fresh for PyCon US 2017, the attrs team is relieved to present you the much-delayed attrs 17.1.0!
Full changes: http://www.attrs.org/en/stable/changelog.html
***
First the bad news: until 17.1.0, attrs’ logic regarding when to create a __hash__ method was in conflict with Python’s specification. If you use instances as dict keys or put them into sets, you have to either make them frozen explicitly by passing `frozen=True` or implicitly by pinky-swearing to not mutate them and force the creation of __hash__ using `hash=True`.
*Please* double check before upgrading!
We’re honestly sorry but didn’t see any better way to handle this. But mind you: hashing mutable objects is a bug so the breakage you’ll encounter may very well be the surfacing of latent, sneaky bugs.
***
Now the good news!
This release took very long (we promise improvement!) which led to the accumulation of a lot of great new features. A few highlights:
# Decorators for validators
>>> @attr.s
... class C(object):
... x = attr.ib()
... @x.validator
... def check(self, attribute, value):
... if value > 42:
... raise ValueError("y must be smaller or equal to 42")
>>> C(42)
C(x=42)
>>> C(43)
Traceback (most recent call last):
...
ValueError: x must be smaller or equal to 42
# Decorators for defaults & self in factories
One of the most requested features: you can base the default of an attribute on a preceding attribute:
>>> @attr.s
... class C(object):
... x = attr.ib(default=1)
... y = attr.ib(default=attr.Factory(lambda self: self.x + 1, takes_self=True))
... z = attr.ib()
... @z.default
... def name_does_not_matter(self):
... return self.x + 1
>>> C()
C(x=1, y=2, z=3)
# New Validators: in_() & and_()
in_() allows to check whether a value is part of an enum or any container:
>>> import enum
>>> class State(enum.Enum):
... ON = "on"
... OFF = "off"
>>> @attr.s
... class C(object):
... state = attr.ib(validator=attr.validators.in_(State))
... val = attr.ib(validator=attr.validators.in_([1, 2, 3]))
>>> C(State.ON, 1)
C(state=<State.ON: 'on'>, val=1)
>>> C("on", 1)
Traceback (most recent call last):
...
ValueError: 'state' must be in <enum 'State'> (got 'on')
>>> C(State.ON, 4)
Traceback (most recent call last):
...
ValueError: 'val' must be in [1, 2, 3] (got 4)
and_() allows you to compose multiple validators to one. As syntactic sugar, you can also just pass a list to `validator=`. Therefore the following lines are equivalent:
x = attr.ib(validator=attr.validators.and_(v1, v2, v3))
x = attr.ib(validator=[v1, v2, v3])
For the attrs team
Hynek
Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread
attrs 17.1.0 Hynek Schlawack <hs@ox.cx> - 2017-05-16 20:23 +0200
csiph-web