Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Hynek Schlawack 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: 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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <845C441B-10BA-43D4-8844-A11405480F74@ox.cx> Xref: csiph.com comp.lang.python.announce:2495 --Apple-Mail=_0037E0C9-3BF9-4D02-B1FD-667B3E96648D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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=E2=80=99 logic regarding when to = create a __hash__ method was in conflict with Python=E2=80=99s = specification. If you use instances as dict keys or put them into sets, = you have to either make them frozen explicitly by passing `frozen=3DTrue` = or implicitly by pinky-swearing to not mutate them and force the = creation of __hash__ using `hash=3DTrue`. *Please* double check before upgrading! We=E2=80=99re honestly sorry but didn=E2=80=99t see any better way to = handle this. But mind you: hashing mutable objects is a bug so the = breakage you=E2=80=99ll 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 =3D 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=3D42) >>> 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 =3D attr.ib(default=3D1) ... y =3D attr.ib(default=3Dattr.Factory(lambda self: self.x + 1, = takes_self=3DTrue)) ... z =3D attr.ib() ... @z.default ... def name_does_not_matter(self): ... return self.x + 1 >>> C() C(x=3D1, y=3D2, z=3D3) # 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 =3D "on" ... OFF =3D "off" >>> @attr.s ... class C(object): ... state =3D attr.ib(validator=3Dattr.validators.in_(State)) ... val =3D attr.ib(validator=3Dattr.validators.in_([1, 2, 3])) >>> C(State.ON, 1) C(state=3D, val=3D1) >>> C("on", 1) Traceback (most recent call last): ... ValueError: 'state' must be in (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=3D`. Therefore the = following lines are equivalent: x =3D attr.ib(validator=3Dattr.validators.and_(v1, v2, v3)) x =3D attr.ib(validator=3D[v1, v2, v3]) For the attrs team Hynek --Apple-Mail=_0037E0C9-3BF9-4D02-B1FD-667B3E96648D Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJZG0OkAAoJEK4lNiJ/afGBvjoP/iUl/d01vg9u0WmGDrVdLdFh z5yZLQyr2/hPOlERadDOZixsh5iFE2hH++E6bvR/hJVfrSpe7oLoFjWOVuI0V1aS o7didb/QOcT7dJ01rBrViJNKg6sL2pyTvQxjiHiZHwrigw3japyRtsZGd91zxBge seCKmXMo8TnmhZ6BcrfIi04DJRHSyyWQygbDk9L1u3fhByUZ/ft2B+RdN9h4sbCi 32xFXPMiqFMMr4kCHPLXgyZD6bK7vgzE7wVQbrPCoxT6QtUHcduv+5gbTAV5bXcQ 5rcqGcJ/LcuSWLed9lqHJTNFq/gsJ4mOyffsGhYbeqmEYhbaVigNOU6/fJV4d0J+ oQFziZCYcnr5SyF7CAbtr4Cium3ldF6EQ6P9AxjYHu+b7hfVUetat0KWppKzKkkX ES0WBPpc6641yrpebIoGI3+xzQdLNrEAvMQaTZ2EEa7h7tX9xYVYfvtyU5abeGGm AuvbzIQFPDWFqOyovzc27XqliL0GJ+qHiRxKOdX5urffqjT2yvJq8lpzl/oqKWbM g6YN7kQFqPGxlsyCgi5OJIihSzjHwNFQ/qDz1QeqBH6qL8XdXub5CksS8d+Vgnfb a9SHSWuFcByGGW66Ky44H1y72ZdVVaYQ89kKv+CrvhhEXMYeKLuFnhq2HmAi0SIu 1sw7pqlC+heF8JklAFvD =1sPD -----END PGP SIGNATURE----- --Apple-Mail=_0037E0C9-3BF9-4D02-B1FD-667B3E96648D--