Re: [Python-ideas] Data Classes

2017-05-19 Thread Niki Spahiev
On 19.05.2017 04:37, Eric V. Smith wrote: On 5/18/17 2:26 PM, Sven R. Kunze wrote: On 17.05.2017 23:29, Ivan Levkivskyi wrote: the idea is to write it into a PEP and consider API/corner cases/implementation/etc. Who's writing it? Guido, Hynek, and I met today. I'm writing up our notes, and

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Eric V. Smith
Could you point me to this 4-point list of Stephan's? I couldn't find anything in the archive that you might be referring to. Never mind, I found them here: https://mail.python.org/pipermail/python-ideas/2017-May/045679.html Eric. ___ Python-ideas ma

Re: [Python-ideas] fnmatch.filter_false

2017-05-19 Thread Wolfgang Maier
On 05/17/2017 07:55 PM, [email protected] wrote: Top posting, apologies. I'm sure there is a better way to do it, and there is a performance hit, but its negligible. This is also a three line delta of the function. from fnmatch import _compile_pattern, filter as old_filter import os impo

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Sven R. Kunze
Exactly this. On 19.05.2017 14:42, Eric V. Smith wrote: Could you point me to this 4-point list of Stephan's? I couldn't find anything in the archive that you might be referring to. Never mind, I found them here: https://mail.python.org/pipermail/python-ideas/2017-May/045679.html Eric.

Re: [Python-ideas] fnmatch.filter_false

2017-05-19 Thread tritium-list
> -Original Message- > From: Python-ideas [mailto:python-ideas-bounces+tritium- > [email protected]] On Behalf Of Wolfgang Maier > Sent: Friday, May 19, 2017 10:03 AM > To: [email protected] > Subject: Re: [Python-ideas] fnmatch.filter_false > > On 05/17/2017 07:55 PM, > t

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Guido van Rossum
For people who don't want to click on links: 1. Allow hash and equality to be based on object identity, rather than structural identity, this is very important if one wants to store un-hashable objects in the instance. (In my case: mostly dict's and numpy arrays). 2. Not subclassed from tupl

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Stephan Houben
Let me quote the attrs docs: "" convert (callable) – callable() that is called by attrs-generated __init__ methods to convert attribute’s value to the desired format. It is given the passed-in value, and the returned value will be used as the new value of the attribute. The value is converted befo

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Guido van Rossum
So it is only called by __init__ and not by __setattr__? On Fri, May 19, 2017 at 11:32 AM, Stephan Houben wrote: > Let me quote the attrs docs: > > "" > convert (callable) – callable() that is called by attrs-generated __init__ > methods to convert attribute’s value to the desired format. It is

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Stephan Houben
Hi Guido, Yes indeed, *only* invoked by __init__ . See my test below. = import attr @attr.s class Foo: x = attr.ib(convert=str) foo = Foo(42) print(repr(foo.x)) # prints '42' foo.x = 42 print(repr(foo.x)) # prints 42 == Not sure if this is a good design but it matches the docs. St

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Tin Tvrtković
Hello, I'm an attrs contributor so maybe I can clear up any questions. Convert callables are only called in __init__, not in the setters. We've had this requested a number of times and we will almost certainly support it in the future, probably on an opt-in basis. The reason we don't currently s

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Sven R. Kunze
Just one additional word about mixins: we've been inspired by Django's extensive usage of mixins for their class-based views, forms and model classes. For one, we defined more mixins for those classes (like UrlMixin for view classes), and for another we developed our own mixin infrastructure f

Re: [Python-ideas] JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)

2017-05-19 Thread Steven D'Aprano
On Fri, May 19, 2017 at 11:24:53AM -0700, Guido van Rossum wrote: > 4. Easily allow to specify a conversion function. For example I have > some code like below: > note that I can store a numpy array while keeping hashability and > I can make it convert >to a numpy array in the constructor.