03-25-2011, 10:39 AM | #1 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Change to except clauses
I see this week a lot of except Exception, e within the Calibre codebase has been changed to except Exception as e
Is this a cosmetic thing or some sort of required Python version thing? Do I need to make similar changes to my plugins and any of their dependent libs and push new versions out? |
03-25-2011, 01:17 PM | #2 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
It's a new syntax introduced in python 2.6 and 3.x. It's a little clearer than the old syntax was, especially in the case of catching multiple exception types. You do not have to make the change in your code as long as calibre continues to use python 2.x, which it will for a long time.
|
Advert | |
|
03-25-2011, 01:24 PM | #3 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thx Kovid, I'll make the change and let it just be included in any next version when it naturally goes out.
I also found that for my Manage Series plugin that the ordered_dict.py I used to reference it from disappeared, and changed the code to use from collections instead. I am guessing more legacy code cleanup to take advantage of later Python again? Any other things that come to mind? As a lot of my Python coding has come from what I have seen in Calibre that means your issues become my issues sometimes |
03-25-2011, 01:32 PM | #4 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Yeah ordered_dict was removed as it's part of the python stdlib now. I didn't realize you would be using that as it has existed in the stdlib for a while. I tend to forget that not everyone is as immersed in python as I am
Other cleanups are adding the header: from __future__ import (unicode_literals, division, absolute_import, print_function) to all new code in calibre, this mostly is for python 3 compatibility. The replacing of __import__ with importlib.import_module and trying to remember to use from future_builtins import map wherever I use the map builtin. Apart from ordered_dicts nonoe of the other changes should matter to you unless you want to get the plugin included into the calibre codebase. |
03-25-2011, 01:50 PM | #5 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Oh and I have restored ordered_dict as a stub so that plugins wont break with the next calibre release.
|
Advert | |
|
03-25-2011, 02:36 PM | #6 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thx for all the info Kovid. Yeah us part-time Python numpties are a pain, sorry . Any example I find of usage in the Calibre codebase of something becomes fair game for being copy/pasted or invoked without your understanding of better ways unfortunately.
I'll make sure all my plugins have the code up to date for when they naturally release, sounds like no pressure to force new versions upon people at this point which is cool. |
03-25-2011, 02:41 PM | #7 |
creator of calibre
Posts: 43,871
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No pressure at all, all these changes were prompted by my being in a spring cleaning mood this week
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Break on POV change also, or only on Scene Change? | Steven Lake | Writers' Corner | 2 | 11-27-2010 08:44 PM |
Change requests | mikelv | EPUBReader | 0 | 11-30-2009 01:19 PM |
PRS-600 Change font | hedera | Sony Reader | 4 | 11-18-2009 04:22 PM |
Change the Forum Name? | Hughdal | Sony Reader | 1 | 12-14-2008 09:50 PM |
Change Author | edbro | Sony Reader | 1 | 08-02-2007 09:19 PM |