[Twisted-Python] Python3: should paths be bytes or str?

Wolfgang Rohdewald wolfgang.kde at rohdewald.de
Sun Sep 7 19:26:53 MDT 2014


The porting guide says

No byte paths in sys.path. 

I am not sure what this means, I would assume that
file paths should always be native strings. Or does it mean
that sys.path must only contain ascii bytes?

doc for FilePath says
    On both Python 2 and Python 3, paths can only be bytes.

and svn commit 35410 by itamarst
changed the doc for some path functions in python/filepath.py

from str to bytes

but not all of them:
fgrep 'type path:' filepath.py
    @type path: L{str}
        @type path: L{str}
    @type path: L{bytes}
        @type path: L{bytes}
        @type path: L{bytes}


I stumbled upon this while trying to find out how much work it might be
to make bin/trial run with python3

admin/run-python3-tests already passes for all twisted.spread related
tests but I still need to clean up a lot.

after adding an assert to FilePath.__init__, python3 bin/trial ... gives

  File "/home/wr/ssdsrc/Twisted/twisted/scripts/trial.py", line 601, in run
    config.parseOptions()
  File "/home/wr/ssdsrc/Twisted/twisted/python/usage.py", line 277, in parseOptions
    self.postOptions()
  File "/home/wr/ssdsrc/Twisted/twisted/scripts/trial.py", line 472, in postOptions
    _BasicOptions.postOptions(self)
  File "/home/wr/ssdsrc/Twisted/twisted/scripts/trial.py", line 382, in postOptions
    self['reporter'] = self._loadReporterByName(self['reporter'])
  File "/home/wr/ssdsrc/Twisted/twisted/scripts/trial.py", line 369, in _loadReporterByName
    for p in plugin.getPlugins(itrial.IReporter):
  File "/home/wr/ssdsrc/Twisted/twisted/plugin.py", line 209, in getPlugins
    allDropins = getCache(package)
  File "/home/wr/ssdsrc/Twisted/twisted/plugin.py", line 134, in getCache
    mod = getModule(module.__name__)
  File "/home/wr/ssdsrc/Twisted/twisted/python/modules.py", line 781, in getModule
    return theSystemPath[moduleName]
  File "/home/wr/ssdsrc/Twisted/twisted/python/modules.py", line 702, in __getitem__
    self._findEntryPathString(moduleObject)),
  File "/home/wr/ssdsrc/Twisted/twisted/python/modules.py", line 627, in _findEntryPathString
    if _isPackagePath(FilePath(topPackageObj.__file__)):
  File "/home/wr/ssdsrc/Twisted/twisted/python/filepath.py", line 664, in __init__
    assert isinstance(path, bytes), 'path must be bytes: %r' % (path,)
AssertionError: path must be bytes: '/home/wr/ssdsrc/Twisted/twisted/__init__.py'


-- 
Wolfgang



More information about the Twisted-Python mailing list