On Sat, Mar 6, 2021 at 9:47 AM Ethan Furman wrote:
>
> On 3/5/21 12:41 PM, Caleb Donovick wrote:
> >
> > > __all__ = (Class.__name__, func.__name__, ...)
> > >
> > > So I have to put it at the end of the module. I do this because if I
> > > change the class or function name and I forget to
On 3/5/21 12:41 PM, Caleb Donovick wrote:
> __all__ = (Class.__name__, func.__name__, ...)
>
> So I have to put it at the end of the module. I do this because if I
> change the class or function name and I forget to change it in
> __all__, I get an exception.
I certainly will not claim to
> __all__ = (Class.__name__, func.__name__, ...)
>
> So I have to put it at the end of the module. I do this because if I
> change the class or function name and I forget to change it in
> __all__, I get an exception.
I certainly will not claim to be the arbitrator of good and bad practices
but
On Wed, 3 Mar 2021 at 23:59, Brendan Barnwell wrote:
> But usually you want to define it at the beginning as a sort of
> documentation aid ("this is the public API").
This is a little off-topic, but I'm curious, since usually, for public
functions and classes, I do
__all__ = (Class.__name__,
Why not just __exclude__ or __excluding__?
On Wed, Mar 3, 2021 at 2:57 PM George Harding <
george.winton.hard...@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
>
On 3/3/21 2:18 PM, George Harding wrote:
__all__ does not stop anyone from importing anything in the module using `from
foo import bar`.
That is true, but that is also Python. If you import something not included in
`__all__` then you do so at your own risk as it could change or vanish in
On 3/3/21 3:38 PM, George Harding wrote:
If you are using __all__ to define your API, then you'll end up needing `from
foo import *` if you want to combine modules, e.g.:
https://github.com/python/cpython/blob/master/Lib/asyncio/__init__.py
Absolutely!
So the two need to coexist. *-import
If you are using __all__ to define your API, then you'll end up needing
`from foo import *` if you want to combine modules, e.g.:
https://github.com/python/cpython/blob/master/Lib/asyncio/__init__.py
So the two need to coexist. *-import does have valid uses. The majority of
these cases are
On 3/3/21 2:17 PM, Brendan Barnwell wrote:
[...] usually you want to define [__all__] at the beginning as a sort of
documentation
aid ("this is the public API").
That is its purpose. :-)
I do think something like __exclude_all__ would be handy. It can be annoying
to have
to define
On Thu, Mar 4, 2021 at 9:57 AM Brendan Barnwell wrote:
>
> On 2021-03-03 14:06, Chris Angelico wrote:
> > You could implement that yourself:
> >
> > __all__ = {n for n in globals() if not n.startswith("_")} - __exclude_all__
>
> Sort of. That will only work if you define __all__ at the
On 2021-03-03 14:06, Chris Angelico wrote:
You could implement that yourself:
__all__ = {n for n in globals() if not n.startswith("_")} - __exclude_all__
Sort of. That will only work if you define __all__ at the end of the
file. But usually you want to define it at the beginning as a sort
Hi Ethan,
I'm sorry, I take that back, that convention was codified in PEP8.
https://www.python.org/dev/peps/pep-0008/#id50
Best,
George
On Wed, Mar 3, 2021 at 10:18 PM George Harding <
george.winton.hard...@gmail.com> wrote:
> Hi Ethan,
>
> I'm not convinced that __all__ is responsible for
Hi Ethan,
I'm not convinced that __all__ is responsible for codifying the api. The
contents of __all__, does not stop anyone from importing anything in the
module using `from foo import bar`. __all__ is specified in the tutorial as
being included for the `from foo import *` case:
On Thu, Mar 4, 2021 at 7:57 AM George Harding
wrote:
> 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.
You could implement that yourself:
On 3/3/21 12:55 PM, George Harding wrote:
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 *`.
The primary purpose these days for `__all__` is to codify a module's API. The
*-import is just a
15 matches
Mail list logo