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

2017-06-19 Thread Nick Coghlan
On 19 June 2017 at 04:47, Mahmoud Hashemi wrote: > Barry, that kind of circular import is actually fine in many (if not most) > cases. Modules are immediately created and importable, thenincrementally > populated. The problem arises when you try to do something with contents of > the module that h

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

2017-06-18 Thread Oleg Broytman
On Sun, Jun 18, 2017 at 07:21:21PM +0100, Barry Scott wrote: > I was going to simply keep track of the names of the modules that are being > imported > and raise an exception if an import attempted to import a module that had not > completed > being imported. Please don't do that. In SQLObj

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

2017-06-18 Thread Barry Scott
> On 18 Jun 2017, at 19:21, Barry Scott wrote: > >> >> On 14 Jun 2017, at 07:33, Nick Coghlan > > wrote: >> >> 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 >

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

2017-06-18 Thread Mahmoud Hashemi
Barry, that kind of circular import is actually fine in many (if not most) cases. Modules are immediately created and importable, thenincrementally populated. The problem arises when you try to do something with contents of the module that have not been populated, usually manifesting in the Attribu

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

2017-06-18 Thread Barry Scott
> On 14 Jun 2017, at 07:33, Nick Coghlan wrote: > > 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 :) > > T

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

2017-06-14 Thread Stephan Houben
Huh? The semantics of node.js seem to be completely similar to Python in this respect. In both cases the circular import works if you go through the mutable module object but fails if both modules circularly try to import module members directly. Stephan Op 14 jun. 2017 11:17 a.m. schreef "Abdur

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

2017-06-14 Thread Abdur-Rahmaan Janhangeer
anyways circular imports seem to be making people go for node.js rather than using python . . . Abdur-Rahmaan Janhangeer, Mauritius abdurrahmaanjanhangeer.wordpress.com On 13 Jun 2017 23:04, "Barry Scott" wrote: > Recently I fell into the trap of creating a circular import and yet again > it to

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

2017-06-14 Thread Ivan Levkivskyi
On 14 June 2017 at 09:59, Paul Moore wrote: > On 13 June 2017 at 23:36, Chris Angelico wrote: > > 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 d

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

2017-06-14 Thread Paul Moore
On 13 June 2017 at 23:36, Chris Angelico wrote: > 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 w

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

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 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
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 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] 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 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 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] 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 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] 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