Re: __all__ attribute: bug and proposal

2016-06-28 Thread Ethan Furman
On 06/27/2016 09:31 PM, Zachary Ware wrote: On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico wrote: If you're primarily worried about classes and functions, here's a neat trick you can use: __all__ = [] def all(thing): __all__.append(thing.__name__) return thing Barry

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Zachary Ware
On Mon, Jun 27, 2016 at 7:32 PM, Chris Angelico wrote: > If you're primarily worried about classes and functions, here's a neat > trick you can use: > > __all__ = [] > def all(thing): > __all__.append(thing.__name__) > return thing Barry Warsaw has written

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Steven D'Aprano
On Tue, 28 Jun 2016 12:46 pm, Terry Reedy wrote: > On 6/27/2016 6:29 PM, Pavel S wrote: > >> Frankly, do you always unit-test if __all__ works? > > One should. CPython's test suite includes test___all__. I believe it > imports every stdlib module, looks for __al

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Terry Reedy
On 6/27/2016 6:29 PM, Pavel S wrote: Frankly, do you always unit-test if __all__ works? One should. CPython's test suite includes test___all__. I believe it imports every stdlib module, looks for __all__, and if present, tests that it works. It probably executes 'from mod

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Random832
On Mon, Jun 27, 2016, at 20:32, Chris Angelico wrote: > If you're primarily worried about classes and functions, here's a neat > trick you can use: How about just __all__ = [list of stuff including classes and functions] __all__ = [x if isinstance(x, str) else x.__name__

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Chris Angelico
On Tue, Jun 28, 2016 at 11:55 AM, MRAB wrote: > On 2016-06-28 01:32, Chris Angelico wrote: > [snip] > >> If you're primarily worried about classes and functions, here's a neat >> trick you can use: >> >> __all__ = [] >> def all(thing): >>

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Steven D'Aprano
On Tue, 28 Jun 2016 06:56 am, Pavel S wrote: > Hi, > I today uncovered subtle bug and would like to share it with you. > > By a mistake, I forgot to put comma into '__all__' tuple of some module. > Notice missing comma after 'B'. > > # module foo.py &g

Re: __all__ attribute: bug and proposal

2016-06-27 Thread MRAB
On 2016-06-28 01:32, Chris Angelico wrote: [snip] If you're primarily worried about classes and functions, here's a neat trick you can use: __all__ = [] def all(thing): __all__.append(thing.__name__) return thing Err... won't that hide the 'all' builtin? -

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Chris Angelico
On Tue, Jun 28, 2016 at 6:56 AM, Pavel S wrote: > By a mistake, I forgot to put comma into '__all__' tuple of some module. > Notice missing comma after 'B'. > > # module foo.py > __all__ = ( > 'A', > 'B' > 'C'

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Random832
On Mon, Jun 27, 2016, at 16:56, Pavel S wrote: > Porposal: allow putting objects into __all__ directly, so possible > problems will be found earlier: Question: What happens if the object in __all__ isn't the same object that's in the module? -- https://mail.python.org/mailman

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Chris Angelico
On Tue, Jun 28, 2016 at 8:29 AM, Pavel S wrote: >> but what about integers or strings? > > Can you provide example? Sure. I'll spare you the wall of text that is os.__all__, but here's the types: >>> import os >>> {type(getattr(os, x)).__name__ for x in

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
> but what about integers or strings? Can you provide example? --- No matter if __all__ uses names or objects, I think it should be validated not only when importing '*', but always. Frankly, do you always unit-test if __all__ works? -- https://mail.python.org/mailman/listinfo/python-list

Re: __all__ attribute: bug and proposal

2016-06-27 Thread Chris Angelico
On Tue, Jun 28, 2016 at 6:56 AM, Pavel S wrote: > Porposal: allow putting objects into __all__ directly, so possible problems > will be found earlier: > > # module foo.py > class A: pass > class B: pass > class C: pass > > __all__ = (A, B, C) > > Note: this curr

__all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
Hi, I today uncovered subtle bug and would like to share it with you. By a mistake, I forgot to put comma into '__all__' tuple of some module. Notice missing comma after 'B'. # module foo.py __all__ = ( 'A', 'B' 'C', ) class A: pass

Re: __all__, public API, private stuff, and leading _

2012-05-11 Thread Ethan Furman
Emile van Sebille wrote: On 5/11/2012 9:41 AM Ethan Furman said... Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the

Re: __all__, public API, private stuff, and leading _

2012-05-11 Thread Emile van Sebille
On 5/11/2012 9:41 AM Ethan Furman said... Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? I would, even if only to alert any future maintainer of the internal vs exposed nature of

__all__, public API, private stuff, and leading _

2012-05-11 Thread Ethan Furman
Style question: Since __all__ (if defined) is the public API, if I am using that should I also still use a leading underscore on my private data/functions/etc? ~Ethan~ -- http://mail.python.org/mailman/listinfo/python-list

Re: __all__

2011-08-12 Thread Ethan Furman
, that was the clue I needed. Had to do some thinking since dbf is back to a single module, and no longer a package... here's what I came up with: - class fake_module(object): def __init__(self, name, *args): self.name

Re: __all__

2011-08-09 Thread Paul Woolcock
than Furman wrote: > >> Greetings! >> >> Does anyone know/recall the original purpose of __all__? > > To customise the names available for `from ... import *`: > > http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > > >> I had thought it was

Re: __all__

2011-08-09 Thread Steven D'Aprano
Ethan Furman wrote: > Greetings! > > Does anyone know/recall the original purpose of __all__? To customise the names available for `from ... import *`: http://docs.python.org/whatsnew/2.1.html#other-changes-and-fixes > I had thought it was primarily to specify what would be i

__all__

2011-08-09 Thread Ethan Furman
Greetings! Does anyone know/recall the original purpose of __all__? I had thought it was primarily to specify what would be imported when `from ... import *` was executed, such as for tk; today, it seems it is also used to specify the API for the module, and so the help() subsystem will

Re: Is it bad practise to write __all__ like that

2011-07-29 Thread OKB (not okblacke)
Thomas Rachel wrote: > class AllList(list): > """list which can be called in order to be used as a > __all__-adding > decorator""" Wow, this is a great idea. -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path

Re: Is it bad practise to write __all__ like that

2011-07-29 Thread Karim
On 07/29/2011 08:37 AM, Thomas Rachel wrote: Am 28.07.2011 20:01 schrieb Ian Kelly: The advantage of Thomas's decorator here is that it lets you place the denotation of whether a function is exported alongside its definition, whereas simply declaring the __all__ list forces you to sep

Re: Is it bad practise to write __all__ like that

2011-07-29 Thread mark ferguson
Thomas, A ha! Now I feel all warm and fuzzy inside. It's nice to start the day with learning something new. To be honest, the initial problem was that I didn't understand the meaning of '__all__', again probably from not working in the large with python. After posting, I wen

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Thomas Rachel
Am 28.07.2011 20:01 schrieb Ian Kelly: The advantage of Thomas's decorator here is that it lets you place the denotation of whether a function is exported alongside its definition, whereas simply declaring the __all__ list forces you to separate them. It also avoids the problem of pos

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Erik Max Francis
Thomas Rachel wrote: Why not? But you could even do class AllList(list): """list which can be called in order to be used as a __all__-adding decorator""" def __call__(self, obj): """for decorators""" sel

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Ian Kelly
ace the denotation of whether a function is exported alongside its definition, whereas simply declaring the __all__ list forces you to separate them. It also avoids the problem of possibly mistyping the function's name in the list. -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread mark ferguson
t decorators solved, such that they became an additional tool in the their kit bag? On 28 July 2011 14:00, Karim wrote: > On 07/28/2011 02:29 PM, Thomas Rachel wrote: > >> __all__ = AllList() >> > > Hello Thomas, > > Very beautiful and elegant code. Having both at th

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Karim
On 07/28/2011 02:29 PM, Thomas Rachel wrote: __all__ = AllList() Hello Thomas, Very beautiful and elegant code. Having both at the same time an instance and a method... With this 'small' topic, you taught me something today on property application! Cheers Karim -- http://mail.

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Thomas Rachel
Am 28.07.2011 13:32 schrieb Karim: Hello, __all__ = 'api db input output tcl'.split() or __all__ = """ api db input output tcl """.split() for lazy boy ;o). It is readable as well. What do you think? Why not? But you could even do class AllList(l

Re: Is it bad practise to write __all__ like that

2011-07-28 Thread Ben Finney
Karim writes: > Hello, > > __all__ = 'api db input output tcl'.split() > > or > > __all__ = """ >api >db >input >output > tcl >"&quo

Is it bad practise to write __all__ like that

2011-07-28 Thread Karim
Hello, __all__ = 'api db input output tcl'.split() or __all__ = """ api db input output tcl """.split() for lazy boy ;o). It is readable as well.

Re: __all__ does not work?

2006-05-09 Thread AndyL
> > > Andy> I do not know why but getsize2 is not kept priviate? > > That's not what __all__ is used for. Try this: > > from mm import * > > The only name added to your namespace will be getsize1. > > Skip Okay, got it. Thx. -- http://mail.python.org/mailman/listinfo/python-list

Re: __all__ does not work?

2006-05-09 Thread skip
Andy> This a mm.py module: Andy> _all__=('getsize1',) Andy> size=85 Andy> def getsize1(): Andy> return size Andy> def getsize2(): Andy> return 2*size Andy> I do not know why but getsize2 is not kept priviate? T

__all__ does not work?

2006-05-09 Thread AndyL
This a mm.py module: _all__=('getsize1',) size=85 def getsize1(): return size def getsize2(): return 2*size I do not know why but getsize2 is not kept priviate? $ python Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credi