Opened 11 years ago

Closed 11 years ago

#2037 defect closed duplicate (duplicate)

twisted.python.reflect.namedAny depends on undocumented import implementation details

Reported by: Jean-Paul Calderone Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

In attempting to detect ImportErrors which result from exceptions rather than missing modules, namedAny relies on the fact that CPython's import only uses a single frame for its import logic. If this changes, or if an alternate runtime (for example, PyPy) is used, ImportErrors which stem from the lookup of a module which really does not exist will be re-raised incorrectly.

For example:

Traceback (most recent call last):
  File "runtrial.py", line 4, in <module>
    run()
  File "/Users/stephen/pypy-packages/twisted/scripts/trial.py", line 339, in run
    config = Options()
  File "/Users/stephen/pypy-packages/twisted/scripts/trial.py", line 129, in __init__
    self._loadReporters()
  File "/Users/stephen/pypy-packages/twisted/scripts/trial.py", line 138, in _loadReporters
    for p in plugin.getPlugins(itrial.IReporter):
--- <exception caught here> ---
  File "/Users/stephen/pypy-packages/twisted/plugin.py", line 219, in getPlugins
    adapted = interface(plugin, None)
  File "zope/interface/interface.py", line 679, in __call__
    adapter = conform(self)
  File "/Users/stephen/pypy-packages/twisted/plugin.py", line 77, in __conform__
    return self.load()
  File "/Users/stephen/pypy-packages/twisted/plugin.py", line 72, in load
    return namedAny(self.dropin.moduleName + '.' + self.name)
  File "/Users/stephen/src/Twisted/trunk/twisted/python/reflect.py", line 352, in namedAny
    topLevelPackage = __import__(trialname)
  File "/Users/stephen/src/pypy-fresh/pypy/lib/imp.py", line 208, in __lockedimport__
    return _original_import_hook(modulename, globals, locals, fromlist)
exceptions.ImportError: No module named twisted.plugins.twisted_trial.BlackAndWhite

Change History (4)

comment:1 Changed 11 years ago by jknight

Suggested fix? Look at the actual error message in the exception?

comment:2 Changed 11 years ago by Jean-Paul Calderone

I don't have a better idea yet. Looking at the message is pretty icky, though :(

comment:3 Changed 11 years ago by Jean-Paul Calderone

Resolution: duplicate
Status: newclosed

I suppose this is a duplicate of #698.

comment:4 Changed 7 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.