Why not just __exclude__ or __excluding__?

On Wed, Mar 3, 2021 at 2:57 PM George Harding <george.winton.harding@gmail.com> wrote:
Hi,

Python has an __all__ variable that can be defined in a module to restrict which members of the module should be included in a call `from foo import *`. However specifying which members of the module should be excluded is more difficult. There are three workarounds that I see:

1) Defining __all__ to specify most of the members of the module, except the few that should be excluded.

2) Naming members to be excluded with a leading underscore. e.g. as done here in ctypes: 
https://github.com/python/cpython/blob/master/Lib/ctypes/__init__.py#L3

3) Manually deleting members from the module. e.g. as done here in numpy:
https://github.com/numpy/numpy/blob/master/numpy/core/__init__.py#L52

I think it might be cleaner to also allow an __exclude_all__ variable which will exclude some members from being imported.

If both were defined I would imagine __exclude_all__ being applied second.

Best,

George Harding


_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/YMP7WQ3RI4BW3HUID6JFIOBVAARFA3WL/
Code of Conduct: http://python.org/psf/codeofconduct/