-
Notifications
You must be signed in to change notification settings - Fork 332
Eventlet broke pathlib on Python 3.7 when patches os #534
Copy link
Copy link
Closed
Description
Script to reproduce:
import eventlet
eventlet.monkey_patch(os=True)
from pathlib import Path
Path('.').open()
# Python 3.x: IsADirectoryError: [Errno 21] Is a directory: '.'
# ^ it's ok
# Python 3.7.1: TypeError: open: path should be string, bytes or os.PathLike, not _NormalAccessor
# ^ it's not okAs you can see, Path.open doesn't work on Python 3.7. It's because pathlib uses _NormalAccessor instance, that stores functions from os as attributes:
class _NormalAccessor(_Accessor):
open = os.openPython <3.7 wraps this functions in staticmethod like this:
class _NormalAccessor(_Accessor):
open = staticmethod(os.open)However Python 3.7 doesn't. Python doesn't bound os.open to _NormalAccessor because os.open isn't a function. But when eventlet patches os.open by the custom python function then interpreter bound this function (eventlet.green.os.open) to _NormalAccessor.
I can't report this bug to Python because I can't register on bugs.python.org >.<
Possible solution: patch _NormalAccessor too. But don't forget: in Python 3.6 passed argument has to converted to string:
class _NormalAccessor(_Accessor):
def _wrap_strfunc(strfunc):
@functools.wraps(strfunc)
def wrapped(pathobj, *args):
return strfunc(str(pathobj), *args)
return staticmethod(wrapped)
def _wrap_binary_strfunc(strfunc):
@functools.wraps(strfunc)
def wrapped(pathobjA, pathobjB, *args):
return strfunc(str(pathobjA), str(pathobjB), *args)
return staticmethod(wrapped)
open = _wrap_strfunc(os.open)References:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels