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 Warsaw has

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 a nice

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 __all__, and if present, tests >

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 module import *'.

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__ for x in __all__] --

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 > __all__ = ( > 'A', > 'B' > 'C',

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', > ) > > class A: pass > class B: pass > class C: pass > >

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? --

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 os.__all__} {'bool',

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 currently don't work.

__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 class B: pass class C: pass If you try to import