[Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Barry Scott
Recently I fell into the trap of creating a circular import and yet again it took time to figure out what was wrong. I'm wondering why the python import code does not detect this error and raise an exception. I took a look at the code and got as far as figuring out that I would need to add the

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Antoine Rozo
But circular imports are sometimes needed in modules. For example when you have two classes in two different modules that reference each other in their methods (and because you can't pre-declare classes like in C++). 2017-06-13 20:30 GMT+02:00 Barry Scott : > Recently I fell into the trap of crea

[Python-ideas] Restore the __members__ behavior to python3 for C extension writers

2017-06-13 Thread Barry Scott
I have been trying to get dir(c_ext_obj) to work for PyCXX as the method used with python2 was removed in python3, namely use the list of names returned from the __members__ attribute. I have failed to find a simple replacement for the python3 API. It seems that I have implement __dir__. But to

[Python-ideas] socket module: plain stuples vs named tuples

2017-06-13 Thread Thomas Güttler
AFAIK the socket module returns plain tuples in Python3: https://docs.python.org/3/library/socket.html Why not use named tuples? Regards, Thomas Güttler -- I am looking for feedback for my personal programming guidelines: https://github.com/guettli/programming-guidelines __

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Barry
> On 13 Jun 2017, at 20:13, Antoine Rozo wrote: > > But circular imports are sometimes needed in modules. > For example when you have two classes in two different modules that reference > each other in their methods (and because you can't pre-declare classes like > in C++). Really? It has al

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Chris Angelico
On Wed, Jun 14, 2017 at 6:35 AM, Barry wrote: > On 13 Jun 2017, at 20:13, Antoine Rozo wrote: > > But circular imports are sometimes needed in modules. > For example when you have two classes in two different modules that > reference each other in their methods (and because you can't pre-declare

Re: [Python-ideas] Restore the __members__ behavior to python3 for C extension writers

2017-06-13 Thread Terry Reedy
On 6/13/2017 2:42 PM, Barry Scott wrote: I have been trying to get dir(c_ext_obj) to work for PyCXX as the method used with python2 was removed in python3, namely use the list of names returned from the __members__ attribute. __members__ was deprecated about 15 years ago and gone from the stdl

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Mahmoud Hashemi
I didn't interpret the initial email as wanting an error on *all* circular imports. Merely those which are unresolvable. I've definitely helped people diagnose circular imports and wished there was an error that called that out programmatically, even if it's just a string admonition to check for ci

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Chris Angelico
On Wed, Jun 14, 2017 at 8:10 AM, Mahmoud Hashemi wrote: > I didn't interpret the initial email as wanting an error on *all* circular > imports. Merely those which are unresolvable. I've definitely helped people > diagnose circular imports and wished there was an error that called that out > progra

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Matt
I've also been thinking about this lately. I can remember being confused the first time I saw "ImportError: cannot import name X". As there are multiple things that can cause this error, it took me a while to find a stackoverflow post that suggested that this might be due to circular imports. After

Re: [Python-ideas] Restore the __members__ behavior to python3 for C extension writers

2017-06-13 Thread Chris Angelico
On Wed, Jun 14, 2017 at 8:09 AM, Terry Reedy wrote: > Perhaps you are looking for __dir__, called by dir(). > > " dir([object]) > > Without arguments, return the list of names in the current local scope. > With an argument, attempt to return a list of valid attributes for that > object. > >

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Mahmoud Hashemi
Oh I know the traceback, I've had many brought to my desk by a confused junior dev, looking a lot like yours truly a few years back. :) My only problem with it is that it makes people look at "a.py". And if you look at "a.py", you'll see there's a "q" there. While most of us on this list will chec

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Nick Coghlan
On 14 June 2017 at 08:49, Mahmoud Hashemi wrote: > Oh I know the traceback, I've had many brought to my desk by a confused > junior dev, looking a lot like yours truly a few years back. :) Something worth noting is that as of 3.7, all circular imports that actually *are* resolvable at runtime wil

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Mahmoud Hashemi
That would be amazing! If there's anything I can do to help make that happen, please let me know. It'll almost certainly save that much time for me alone down the line, anyway :) On Tue, Jun 13, 2017 at 7:41 PM, Nick Coghlan wrote: > On 14 June 2017 at 08:49, Mahmoud Hashemi wrote: > > Oh I kno

Re: [Python-ideas] ImportError raised for a circular import

2017-06-13 Thread Nick Coghlan
On 14 June 2017 at 13:02, Mahmoud Hashemi wrote: > That would be amazing! If there's anything I can do to help make that > happen, please let me know. It'll almost certainly save that much time for > me alone down the line, anyway :) The `IMPORT_FROM` opcode's error handling would probably be the