Suggestion for improved ImportError message

Discussion in 'Python' started by Kent Tenney, Aug 13, 2008.

  1. Kent Tenney

    Kent Tenney Guest

    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
     
    Kent Tenney, Aug 13, 2008
    #1
    1. Advertising

  2. Kent Tenney

    Kent Tenney Guest

    > > Then go for it You can prepare a patch and ask on python-dev
    > > if the developers are interested.


    hehe, I'll get a C level patch accepted right after I
    out-swim Mike Phelps.

    > >
    > > I was never hacking the import things on C level before,
    > > but a hint: you have to modify import_from function from
    > > Python/ceval.c


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

    > >
    > > My quick attempt:


    Quick indeed!
    Very cool.

    Thanks,
    Kent
     
    Kent Tenney, Aug 14, 2008
    #2
    1. Advertising

  3. Kent Tenney

    Lie Guest

    On Aug 14, 5:10 pm, Wojtek Walczak
    <> wrote:
    > On Thu, 14 Aug 2008 01:35:44 +0000 (UTC), Kent Tenney wrote:
    > >> > Then go for it  You can prepare a patch and ask on python-dev
    > >> > if the developers are interested.

    >
    > > hehe, I'll get a C level patch accepted right after I
    > > out-swim Mike Phelps.

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

    > >> > I was never hacking the import things on C level before,
    > >> > but a hint: you have to modify import_from function from
    > >> > Python/ceval.c

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

    >
    > I don't know PyPy, but I guess you're right here.
    >
    > --
    > Regards,
    > Wojtek Walczak,http://www.stud.umk.pl/~wojtekwa/
     
    Lie, Aug 15, 2008
    #3
  4. Kent Tenney

    Guest

    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
     
    , Aug 15, 2008
    #4
  5. Kent Tenney

    Benjamin Guest

    On Aug 13, 3:55 pm, Kent Tenney <> wrote:
    > 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.
    >
    > cannot import name annotate from /usr/<snip>/image.pyc
    >
    > Thanks,
    > Kent
     
    Benjamin, Aug 16, 2008
    #5
  6. Kent Tenney

    Lie Guest

    On Aug 15, 7:42 pm, wrote:
    > 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...


    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).

    > Bye,
    > bearophile
     
    Lie, Aug 23, 2008
    #6
  7. Lie wrote:

    >> 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).


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

    </F>
     
    Fredrik Lundh, Aug 23, 2008
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kieran Benton
    Replies:
    3
    Views:
    508
    Ray Cassick \(home\)
    Sep 11, 2003
  2. Franck

    improved ImageButton does it exist?

    Franck, Sep 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    376
    Bruce Barker
    Sep 7, 2005
  3. rich murphy
    Replies:
    12
    Views:
    2,480
  4. DaZoner
    Replies:
    7
    Views:
    99
  5. Irmen de Jong
    Replies:
    2
    Views:
    208
    Irmen de Jong
    Dec 7, 2012
Loading...

Share This Page