[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Ethan Furman
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 d

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread George Harding
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 within

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Ethan Furman
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 __all__

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Chris Angelico
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 en

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Brendan Barnwell
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

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread George Harding
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 c

[Python-ideas] Re: class(obj) could return obj.__class__

2021-03-03 Thread Hans Ginzel
Thank you, type(o) is sufficient. It is possible to use class properties: type(o).__name__ 'c' On Wed, Mar 03, 2021 at 10:03:03PM +, Paul Bryan wrote: Since class is a keyword, this is unlikely. Why is type(o) insufficient? On Wed, 2021-03-03 at 22:59 +0100, Hans Ginzel wrote: >>> class

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread George Harding
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: https://docs.pyt

[Python-ideas] Re: class(obj) could return obj.__class__

2021-03-03 Thread Paul Bryan
Err, why is it insufficient? On Wed, 2021-03-03 at 14:03 -0800, Paul Bryan wrote: > Since class is a keyword, this is unlikely. Why is type(o) not > insufficient? > > On Wed, 2021-03-03 at 22:59 +0100, Hans Ginzel wrote: > > > > > class c: pass > > > > > o = c() > > > > > o.__class__ > > > > > >

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Chris Angelico
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: _

[Python-ideas] Re: class(obj) could return obj.__class__

2021-03-03 Thread Paul Bryan
Since class is a keyword, this is unlikely. Why is type(o) not insufficient? On Wed, 2021-03-03 at 22:59 +0100, Hans Ginzel wrote: > > > > class c: pass > > > > o = c() > > > > o.__class__ > > > > > class(o) >     File "", line 1 >   class(o) >    ^ > SyntaxError: invalid syntax

[Python-ideas] class(obj) could return obj.__class__

2021-03-03 Thread Hans Ginzel
Please, consider class(obj) to return obj.__class__ consistenly with dir(), vars(), repr(), str(),… class c: pass o = c() o.__class__ class(o) File "", line 1 class(o) ^ SyntaxError: invalid syntax Thank you in advance, H. ___ Py

[Python-ideas] Re: Add an __exclude_all__ complement to __all__

2021-03-03 Thread Ethan Furman
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

[Python-ideas] Re: Fwd: [Python-Dev] Suggestion About Python Syntax

2021-03-03 Thread anthony.flury via Python-ideas
Dear Anthony, Greetings from another Anthony (although my friends call me Tony). Thank you for your suggestion about changes to the Python Syntax. The Idea of having curly braces with blocks of code has been considered many times, and every time it has not been accepted. When you do enough p

[Python-ideas] Add an __exclude_all__ complement to __all__

2021-03-03 Thread George Harding
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 __a

[Python-ideas] Re: list.extend() should return self

2021-03-03 Thread Matthias Bussonnier
Methods that mutate their argument typically return None, to avoid confusing them with methods that return copies; If you both mutate and return a copy it is easy to end up with shared objects in place you actually don't want them >>> even = [2,4,6] >>> odd = [1,3,5] >>> all = odd.extend(even) .

[Python-ideas] Re: list.extend() should return self

2021-03-03 Thread Richard Damon
On 3/3/21 3:23 PM, Hans Ginzel wrote: > Please, is there a reason why extend() method does not return self? > a = [1,2].extend((3,4)) a type(a) > b = [1,2] b.extend((3,4)) b > [1, 2, 3, 4] I think it just the general principle that mutating methods return None, whil

[Python-ideas] list.extend() should return self

2021-03-03 Thread Hans Ginzel
Please, is there a reason why extend() method does not return self? a = [1,2].extend((3,4)) a type(a) b = [1,2] b.extend((3,4)) b [1, 2, 3, 4] ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le.

[Python-ideas] Re: Integer concatenation to byte string

2021-03-03 Thread Random832
On Wed, Mar 3, 2021, at 04:09, Barry Scott wrote: > I was thinking of the C functions that are executed in ceval.c to run > the interpreter for any byte code. In that case, it's not clear how your proposed syntax would not have the same overhead [especially your suggestion of a += operator]

[Python-ideas] Fwd: [Python-Dev] Suggestion About Python Syntax

2021-03-03 Thread George Harding
-- Forwarded message - From: Anthony Farino Date: Wed, Mar 3, 2021 at 5:52 PM Subject: [Python-Dev] Suggestion About Python Syntax To: I love the Python scripting language, but there’s something that would make it much better. Almost every other programming language uses curly b

[Python-ideas] Re: Integer concatenation to byte string

2021-03-03 Thread Barry Scott
> On 2 Mar 2021, at 23:49, Steven D'Aprano wrote: > > > [Barry] >> All python byte code is interpreted by calling functions. They take >> time and resources. > > That's not entirely correct. Literals such as text strings, ints and > floats get compiled directly into the byte-code. Now of c