Suggestion for improved ImportError message

K

Kent Tenney

Howdy,

I was just bit by

from image import annotate

ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which made it clear that the wrong image module had been found.

It would be nice if ImportError announced this up front.

cannot import name annotate from /usr/<snip>/image.pyc

Thanks,
Kent
 
K

Kent Tenney

Then go for it You can prepare a patch and ask on python-dev
hehe, I'll get a C level patch accepted right after I
out-swim Mike Phelps.

Am I correct in thinking that PyPy would mean low level
stuff like this will be Python instead of C?
That would be nice.

Quick indeed!
Very cool.

Thanks,
Kent
 
L

Lie

It's really not that hard. The only hard thing (harder than
writing the code) might be to win the acceptance of the core
developers that this change is really needed ;-)

I think the acceptance for this wouldn't be that hard since there is
no real issue for regression (the only one I could think of is for
doctest module, although I'm not sure there are any reason to test for
failed import in doctest)
 
B

bearophileHUGS

Lie:
I'm not sure there are any reason to test for failed import in doctest)<

I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations...

Bye,
bearophile
 
B

Benjamin

Howdy,

I was just bit by

from image import annotate

ImportError: cannot import name annotate

I found the problem via

import image
print image.__file__

which made it clear that the wrong image module had been found.

It would be nice if ImportError announced this up front.

Why? It says the file where the error originated in the traceback.
 
L

Lie

Lie:


I have code that uses numpy if available, otherwise uses slower normal
Python code. Inside the doctests I'd like to test both situations...

Why? Is there a difference in result if you have used numpy and python
code? If that is, I smell a bad code. What numpy and python code
version would return in that situation should be the same (practically
it isn't always feasible though).
 
F

Fredrik Lundh

Lie said:
Why? Is there a difference in result if you have used numpy and python
code? If that is, I smell a bad code. What numpy and python code
version would return in that situation should be the same (practically
it isn't always feasible though).

maybe the point is to use doctest to *verify* that the code generates
the same result whether or not numpy is used?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top