This probably won’t make sense without an example. I’m using python-disqus in my Django app, and I’m wrapping it to better decouple it from the rest of my application.
I have a file, disqus.py, which imports disqusapi and defines a number of helper functions. Elsewhere in the application code I can simply add from mango import disqus, but in a few places it’s necessary to capture exceptions which may be raised when making API calls. This means that I’m forced to do something like:
from disqusapi import APIError
from mango import disqus
try:
disqus.thread.fetch(1)
except APIError, error:
logger.warn('Disqus API error: %s' % error)
If instead I were to import APIError at the top of disqus.py, I could instead write:
from mango import disqus
try:
disqus.thread.fetch(1)
except disqus.APIError, error:
logger.warn('Disqus API error: %s' % error)
Pyflakes complains about the unused import, but this seems like a reasonable thing to do. Should I happily ignore Pyflakes here, or am I missing a better option?
To be clear, I don’t need to modify disqusapi.APIError in any way, so subclassing is unnecessary.
Short answer: No.
Long answer, if you are writing a wrapper to make your own code simpler and easier for you to understand you can do whatever you like. If you want to wrap other code, or import modules and subclass them, or import modules, and change their methods.
If you’re writing code for other people, you probably want to add comments to explain what you’re doing. If it’s just for yourself, it’s all good.