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

2017-05-17 Thread Michel Desmoulin
Le 17/05/2017 à 07:22, Guido van Rossum a écrit : > On Tue, May 16, 2017 at 8:14 PM, Juancarlo Añez > wrote: > > What I like about attrs is: > > * The class level declaration of instance attributes > * That the reasonable *init*, *repr*, and *eq* are g

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

2017-05-17 Thread Stéfane Fermigier
(Not Stephen either). I've been using attrs for some time now, but only superficially. I'm not sure yet if I want to make it mandatory for my team or not. My biggest issues so far are: - how to truly leverage it with a declarative ORM? (SQLAlchemy in my case, the workaround being to only use a s

Re: [Python-ideas] PEP 526: why ClassVar instead of ClassAttr?

2017-05-17 Thread Steven D'Aprano
On Tue, May 16, 2017 at 10:11:31PM -0700, Guido van Rossum wrote: > There was another reason too. Many things are "class attributes" e.g. > methods, descriptors. But only specific things are class *variables*. Ah, that's a good reason. I can live with that. Thanks for the explanation. -- Stev

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

2017-05-17 Thread Eric V. Smith
On 5/16/17 5:04 PM, Guido van Rossum wrote: Stephen, What features of attrs specifically solve your use cases? Also not Stephan! As others have said, it's the "tupleness" of namedtuple that has bitten me. Also, option mutability is key for my use cases. One use case that attrs satisfies (as

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

2017-05-17 Thread Stephan Houben
Hi Michel, > Now OPP is already hard to teach to my students, but if I have to add > this to the mix, I will just have to tell them to copy / paste it > blindly for a long time before I can get to the point they can > understand what it does. About the teachability, some remarks: 1. You can still

Re: [Python-ideas] PEP 526: why ClassVar instead of ClassAttr?

2017-05-17 Thread Nick Coghlan
On 17 May 2017 at 19:03, Steven D'Aprano wrote: > On Tue, May 16, 2017 at 10:11:31PM -0700, Guido van Rossum wrote: >> There was another reason too. Many things are "class attributes" e.g. >> methods, descriptors. But only specific things are class *variables*. > > Ah, that's a good reason. I can

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

2017-05-17 Thread Michel Desmoulin
Le 17/05/2017 à 13:08, Stephan Houben a écrit : > Hi Michel, > >> Now OPP is already hard to teach to my students, but if I have to add >> this to the mix, I will just have to tell them to copy / paste it >> blindly for a long time before I can get to the point they can >> understand what it doe

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

2017-05-17 Thread Nick Coghlan
On 17 May 2017 at 13:14, Juancarlo Añez wrote: > On Tue, May 16, 2017 at 5:04 PM, Guido van Rossum > wrote: > What I like about attrs is: > > * The class level declaration of instance attributes > * That the reasonable init, repr, and eq are generated These are also the two main benefits for my

[Python-ideas] Running C extension modules using -m switch

2017-05-17 Thread gmarcel . plch
Greetings, I'm a student that has been working lately on feature of the runpy module that I have been quite interested in: execution of extension modules using the -m switch. Currently this requires access to the module's code, so it only works for modules written in Python. I have a proof-of-conc

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

2017-05-17 Thread Boris Borcic
Chris Angelico wrote: # Python def outer(): x = 0 def inner(): nonlocal x x += 2 Is it better to say "nonlocal" on everything you use than to say "self.x" on each use? I've not used Python closures since nonlocal came about, but AFAIK you only need to use nonlocal if th

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

2017-05-17 Thread Stephan Houben
Hi Michel, > Comparing setting instance attributes to metaclasses is pushing it don't > you think ? My only point is that there are aspects of the core Python language which are probably not covered by your course (and I chose metaclasses as a topic least likely to be covered in a beginner's cour

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

2017-05-17 Thread Chris Angelico
On Wed, May 17, 2017 at 11:08 PM, Boris Borcic wrote: > Chris Angelico wrote: >> >> # Python >> def outer(): >> x = 0 >> def inner(): >> nonlocal x >> x += 2 >> >> Is it better to say "nonlocal" on everything you use than to say >> "self.x" on each use? > > > I've not used

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

2017-05-17 Thread Eric V. Smith
On 5/17/17 2:11 AM, Eric V. Smith wrote: One use case that attrs satisfies (as does namedtuple) that I'd like to make sure we allow for in any solution is dynamically creating classes where you don't know the field names until runtime. I run in to this when reading anything with columnar metadata

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

2017-05-17 Thread Todd
On May 17, 2017 04:16, "Michel Desmoulin" wrote: Le 17/05/2017 à 07:22, Guido van Rossum a écrit : > On Tue, May 16, 2017 at 8:14 PM, Juancarlo Añez > wrote: > > What I like about attrs is: > > * The class level declaration of instance attributes > * T

[Python-ideas] fnmatch.filter_false

2017-05-17 Thread Alex Walters
Fnmath.filter works great. To remind people what it does, it takes an iterable of strings and a pattern and returns a list of the strings that match the pattern. And that is wonderful However, I often need to filter *out* the items that match the pattern (to ignore them). In every project that

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

2017-05-17 Thread Sven R. Kunze
On 17.05.2017 13:37, Michel Desmoulin wrote: Having a cleaner, faster solution to declare a class would be awesome, both for dev and for teaching. That's why we all love attrs. But we are talking here about a nice-to-have feature. Python works perfectly fine without it. But since we are at it, l

Re: [Python-ideas] PEP 526: why ClassVar instead of ClassAttr?

2017-05-17 Thread Ivan Levkivskyi
On 17 May 2017 at 11:03, Steven D'Aprano wrote: > On Tue, May 16, 2017 at 10:11:31PM -0700, Guido van Rossum wrote: > > There was another reason too. Many things are "class attributes" e.g. > > methods, descriptors. But only specific things are class *variables*. > > Ah, that's a good reason. I c

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

2017-05-17 Thread Stephan Houben
Hi Sven, > But even given that (and I am only speaking for my team), I haven't even > seen a use-case for namedtuples in a year. Every time we considered it, > people said: "please make it its own class for documentary purposes; this > thing will tend to grow faster than we can imagine". Using na

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread Oleg Broytman
On Wed, May 17, 2017 at 12:14:05PM -0400, Alex Walters wrote: > Fnmath.filter works great. To remind people what it does, it takes an > iterable of strings and a pattern and returns a list of the strings that > match the pattern. And that is wonderful > > However, I often need to filter *out*

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

2017-05-17 Thread Ivan Levkivskyi
On 17 May 2017 at 18:38, Stephan Houben wrote: > Hi Sven, > > > But even given that (and I am only speaking for my team), I haven't even > > seen a use-case for namedtuples in a year. Every time we considered it, > > people said: "please make it its own class for documentary purposes; this > > th

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread tritium-list
> -Original Message- > From: Python-ideas [mailto:python-ideas-bounces+tritium- > list=sdamon@python.org] On Behalf Of Oleg Broytman > Sent: Wednesday, May 17, 2017 12:44 PM > To: python-ideas@python.org > Subject: Re: [Python-ideas] fnmatch.filter_false > > On Wed, May 17, 2017 at 12:

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

2017-05-17 Thread Ethan Furman
On 05/17/2017 06:20 AM, Stephan Houben wrote: class MyClass: foo = attr.ib() MyClass = attr.s(MyClass) Given that one of Python's great strengths is its readability, I would not use the attr library in teaching because it is not. Having a dot in the middle of words is confusing, especi

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

2017-05-17 Thread Ivan Levkivskyi
On 17 May 2017 at 19:40, Juancarlo Añez wrote: > > On Wed, May 17, 2017 at 12:48 PM, Ivan Levkivskyi > wrote: > >> class Foo(NamedTuple): >> """Foo is a very important class and >> you should totally use it. >> """ >> bar: int >> baz: int = 0 >> >> def grand_total(self):

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

2017-05-17 Thread Juancarlo Añez
On Wed, May 17, 2017 at 12:48 PM, Ivan Levkivskyi wrote: > class Foo(NamedTuple): > """Foo is a very important class and > you should totally use it. > """ > bar: int > baz: int = 0 > > def grand_total(self): > return self.bar + self.baz > Really?! I didn't know

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

2017-05-17 Thread Sven R. Kunze
On 17.05.2017 19:30, Ethan Furman wrote: Given that one of Python's great strengths is its readability, I would not use the attr library in teaching because it is not. Having a dot in the middle of words is confusing, especially when you don't already have a basis for which abbreviations are c

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

2017-05-17 Thread Sven R. Kunze
Hi Stephan, hi Ivan, On 17.05.2017 18:48, Ivan Levkivskyi wrote: from typing import NamedTuple class Foo(NamedTuple): """Foo is a very important class and you should totally use it. """ bar: int baz: int = 0 def grand_total(self): return self.bar + self.baz typ

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread tritium-list
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 import os.path import posixpath data = os.listdir() def fi

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

2017-05-17 Thread Stephan Houben
If this is the *only* objection to attrs let me quote some documentation: """ If playful naming turns you off, attrs comes with serious business aliases: >>> from attr import attrs, attrib >>> @attrs ... class SeriousCoordinates(object): ... x = attrib() ... y = attrib() """ So attrs and

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

2017-05-17 Thread Oleg Broytman
On Wed, May 17, 2017 at 07:39:36PM +0200, "Sven R. Kunze" wrote: > It took me 5 days to see "foo = attrib()" in "foo = attr.ib()" What the > hell means "ib"? ... Guido has named it "deadly cute". (-: > Sven Oleg. -- Oleg Broytmanhttp://phdru.name/p...@phdru

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

2017-05-17 Thread Sven R. Kunze
On 17.05.2017 19:55, Stephan Houben wrote: So attrs and attrib can be used as alternatives for attr.s and attr.ib . Personally, I like the playful names. Ah, now I understand their documentation. :D I read this passage and thought: "where is the difference. Maybe, they meant omitting x=, y= in

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

2017-05-17 Thread Stephan Houben
Hi Sven, "I hope the second ': int' can be omitted because 0 already is an int." 0 is also an Any, an object, a SupportAbs, and a Union[int, str]. And infinitely more, of course. A typechecker needs to be explicitly told which was intended. Stephan Op 17 mei 2017 19:52 schreef "Sven R. Kunze"

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

2017-05-17 Thread Sven R. Kunze
Hi Stephan, On 17.05.2017 08:49, Stephan Houben wrote: 2. Not subclassed from tuple. I have been bitten by this subclassing when trying to set up singledispatch on sequences and also on my classes. Would it make sense to have a 'simpleobject'? Which basically implements a NamedTuple const

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread אלעזר
There shouldn't be any difference at all. Checking the for invert can be outside of the loop, which will make the loop itself exactly as it is now. Just like what's been done with normcase. On Wed, May 17, 2017 at 8:55 PM wrote: > Top posting, apologies. > > I'm sure there is a better way to do

[Python-ideas] [semi-OT] NamedTuple from aenum library [was: JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)]

2017-05-17 Thread Ethan Furman
On 05/17/2017 10:43 AM, Ivan Levkivskyi wrote: On 17 May 2017 at 19:40, Juancarlo Añez wrote: On Wed, May 17, 2017 at 12:48 PM, Ivan Levkivskyi wrote: class Foo(NamedTuple): """Foo is a very important class and you should totally use it. """ bar: int baz: int = 0

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

2017-05-17 Thread Ivan Levkivskyi
On 17 May 2017 at 20:09, Sven R. Kunze wrote: > Hi Stephan, > > On 17.05.2017 08:49, Stephan Houben wrote: > >> 2. Not subclassed from tuple. I have been bitten by this subclassing >> when trying to set up >> singledispatch on sequences and also on my classes. >> > > Would it make sense to ha

Re: [Python-ideas] [semi-OT] NamedTuple from aenum library [was: JavaScript-Style Object Creation in Python (using a constructor function instead of a class to create objects)]

2017-05-17 Thread Ethan Furman
On 05/17/2017 02:06 PM, Ethan Furman wrote: You might want to check out the NamedTuple class from my aenum [1] library [1] https://pypi.python.org/pypi/aenum -- ~Ethan~ ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/ma

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread Steven D'Aprano
On Wed, May 17, 2017 at 12:14:05PM -0400, Alex Walters wrote: > Fnmath.filter works great. To remind people what it does, it takes an > iterable of strings and a pattern and returns a list of the strings that > match the pattern. And that is wonderful > > However, I often need to filter *out* th

Re: [Python-ideas] fnmatch.filter_false

2017-05-17 Thread tritium-list
> -Original Message- > From: Python-ideas [mailto:python-ideas-bounces+tritium- > list=sdamon@python.org] On Behalf Of Steven D'Aprano > Sent: Wednesday, May 17, 2017 9:01 PM > To: python-ideas@python.org > Subject: Re: [Python-ideas] fnmatch.filter_false > > On Wed, May 17, 2017 at