I think the easiest and most sensible way to address http://bugs.python.org/issue9353 is to simply remove the __all__ definition from argparse - everything that doesn't start with an underscore in the module is already meant to be exposed. But then I wonder - is __all__ considered part of the public API of a module? Or is it okay to just remove it and assume that no one should have been accessing it directly anyway? Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
On 01/11/2010 14:48, Steven Bethard wrote:
I think the easiest and most sensible way to address http://bugs.python.org/issue9353 is to simply remove the __all__ definition from argparse - everything that doesn't start with an underscore in the module is already meant to be exposed.
But then I wonder - is __all__ considered part of the public API of a module? Or is it okay to just remove it and assume that no one should have been accessing it directly anyway?
Isn't it better to add the missing elements - what is the problem with that approach? Not defining __all__ will mean that "from argparse import *" will also export all the modules you import (copy, os, re, sys, textwrap). All the best, Michael
Steve
-- http://www.voidspace.org.uk/ READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.
On Mon, Nov 1, 2010 at 2:53 PM, Michael Foord
On 01/11/2010 14:48, Steven Bethard wrote:
I think the easiest and most sensible way to address http://bugs.python.org/issue9353 is to simply remove the __all__ definition from argparse - everything that doesn't start with an underscore in the module is already meant to be exposed.
But then I wonder - is __all__ considered part of the public API of a module? Or is it okay to just remove it and assume that no one should have been accessing it directly anyway?
Isn't it better to add the missing elements - what is the problem with that approach?
It just requires extra synchronization, and history shows that I always forget to add them. ;-)
Not defining __all__ will mean that "from argparse import *" will also export all the modules you import (copy, os, re, sys, textwrap).
That won't happen in the case of argparse - all modules are imported like "import os as _os". Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
On Mon, Nov 01, 2010 at 02:55:25PM +0000, Steven Bethard wrote:
On Mon, Nov 1, 2010 at 2:53 PM, Michael Foord
wrote: Isn't it better to add the missing elements - what is the problem with that approach?
It just requires extra synchronization, and history shows that I always forget to add them. ;-)
Automate: for key, value in globals().items(): if not key.startswith('_'): __all__.append(key) Further filter (by key or value) to your needs. Oleg. -- Oleg Broytman http://phd.pp.ru/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Mon, Nov 1, 2010 at 7:53 AM, Michael Foord
On 01/11/2010 14:48, Steven Bethard wrote:
I think the easiest and most sensible way to address http://bugs.python.org/issue9353 is to simply remove the __all__ definition from argparse - everything that doesn't start with an underscore in the module is already meant to be exposed.
But then I wonder - is __all__ considered part of the public API of a module? Or is it okay to just remove it and assume that no one should have been accessing it directly anyway?
Isn't it better to add the missing elements - what is the problem with that approach?
Agreed, that's what I would do.
Not defining __all__ will mean that "from argparse import *" will also export all the modules you import (copy, os, re, sys, textwrap).
Well, the copy of argparse.py that I have carefully renames those to _copy, _os etc. to avoid this. You never know. It is also possible to write automated tests that flag likely missing symbols in __all__ (as well as symbols in __all__ missing from the module). -- --Guido van Rossum (python.org/~guido)
On Mon, Nov 1, 2010 at 2:57 PM, Guido van Rossum
On Mon, Nov 1, 2010 at 7:53 AM, Michael Foord
wrote: On 01/11/2010 14:48, Steven Bethard wrote:
But then I wonder - is __all__ considered part of the public API of a module? Or is it okay to just remove it and assume that no one should have been accessing it directly anyway?
Isn't it better to add the missing elements - what is the problem with that approach?
Agreed, that's what I would do.
Ok, sounds good.
It is also possible to write automated tests that flag likely missing symbols in __all__ (as well as symbols in __all__ missing from the module).
Yep, I plan on doing that. I already had a test something like this to remind me how I broke __all__ before. ;-) Steve -- Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
On 01/11/2010 14:57, Guido van Rossum wrote:
[snip...]
Not defining __all__ will mean that "from argparse import *" will also export all the modules you import (copy, os, re, sys, textwrap). Well, the copy of argparse.py that I have carefully renames those to _copy, _os etc. to avoid this.
Bah.... Sorry about that. Michael -- http://www.voidspace.org.uk/ READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.
On Tue, Nov 2, 2010 at 12:57 AM, Guido van Rossum
It is also possible to write automated tests that flag likely missing symbols in __all__ (as well as symbols in __all__ missing from the module).
These days, test___all__ checks that everything in __all__ exists in standard library modules. It is also possible for individual module tests to include a check that goes the other way along the lines of: def test_all_is_complete(): known_private = {"known", "unexported", "names"} expected_public = (k for k in mod.__dict__ if k not in known_private and not k.startswith("_")) self.assertEqual(set(mod.__all__), expected_public) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
participants (5)
-
Guido van Rossum
-
Michael Foord
-
Nick Coghlan
-
Oleg Broytman
-
Steven Bethard