[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2022-10-19 14:19:24 +00:00 committed by Anthony Sottile
parent 19dda7c9bd
commit 49abbf2485
4 changed files with 389 additions and 328 deletions

View File

@ -2,41 +2,49 @@
create errno-specific classes for IO or os calls. create errno-specific classes for IO or os calls.
""" """
import errno
import os
import sys
from types import ModuleType from types import ModuleType
import sys, os, errno
class Error(EnvironmentError): class Error(EnvironmentError):
def __repr__(self): def __repr__(self):
return "%s.%s %r: %s " %(self.__class__.__module__, return "{}.{} {!r}: {} ".format(
self.__class__.__name__, self.__class__.__module__,
self.__class__.__doc__, self.__class__.__name__,
" ".join(map(str, self.args)), self.__class__.__doc__,
#repr(self.args) " ".join(map(str, self.args)),
) # repr(self.args)
)
def __str__(self): def __str__(self):
s = "[%s]: %s" %(self.__class__.__doc__, s = "[{}]: {}".format(
" ".join(map(str, self.args)), self.__class__.__doc__,
) " ".join(map(str, self.args)),
)
return s return s
_winerrnomap = { _winerrnomap = {
2: errno.ENOENT, 2: errno.ENOENT,
3: errno.ENOENT, 3: errno.ENOENT,
17: errno.EEXIST, 17: errno.EEXIST,
18: errno.EXDEV, 18: errno.EXDEV,
13: errno.EBUSY, # empty cd drive, but ENOMEDIUM seems unavailiable 13: errno.EBUSY, # empty cd drive, but ENOMEDIUM seems unavailiable
22: errno.ENOTDIR, 22: errno.ENOTDIR,
20: errno.ENOTDIR, 20: errno.ENOTDIR,
267: errno.ENOTDIR, 267: errno.ENOTDIR,
5: errno.EACCES, # anything better? 5: errno.EACCES, # anything better?
} }
class ErrorMaker(ModuleType): class ErrorMaker(ModuleType):
""" lazily provides Exception classes for each possible POSIX errno """lazily provides Exception classes for each possible POSIX errno
(as defined per the 'errno' module). All such instances (as defined per the 'errno' module). All such instances
subclass EnvironmentError. subclass EnvironmentError.
""" """
Error = Error Error = Error
_errno2class = {} _errno2class = {}
@ -52,23 +60,25 @@ class ErrorMaker(ModuleType):
try: try:
return self._errno2class[eno] return self._errno2class[eno]
except KeyError: except KeyError:
clsname = errno.errorcode.get(eno, "UnknownErrno%d" %(eno,)) clsname = errno.errorcode.get(eno, "UnknownErrno%d" % (eno,))
errorcls = type(Error)(clsname, (Error,), errorcls = type(Error)(
{'__module__':'py.error', clsname,
'__doc__': os.strerror(eno)}) (Error,),
{"__module__": "py.error", "__doc__": os.strerror(eno)},
)
self._errno2class[eno] = errorcls self._errno2class[eno] = errorcls
return errorcls return errorcls
def checked_call(self, func, *args, **kwargs): def checked_call(self, func, *args, **kwargs):
""" call a function and raise an errno-exception if applicable. """ """call a function and raise an errno-exception if applicable."""
__tracebackhide__ = True __tracebackhide__ = True
try: try:
return func(*args, **kwargs) return func(*args, **kwargs)
except self.Error: except self.Error:
raise raise
except (OSError, EnvironmentError): except OSError:
cls, value, tb = sys.exc_info() cls, value, tb = sys.exc_info()
if not hasattr(value, 'errno'): if not hasattr(value, "errno"):
raise raise
__tracebackhide__ = False __tracebackhide__ = False
errno = value.errno errno = value.errno
@ -83,9 +93,9 @@ class ErrorMaker(ModuleType):
cls = self._geterrnoclass(_winerrnomap[errno]) cls = self._geterrnoclass(_winerrnomap[errno])
except KeyError: except KeyError:
raise value raise value
raise cls("%s%r" % (func.__name__, args)) raise cls(f"{func.__name__}{args!r}")
__tracebackhide__ = True __tracebackhide__ = True
error = ErrorMaker('_pytest._py.error') error = ErrorMaker("_pytest._py.error")
sys.modules[error.__name__] = error sys.modules[error.__name__] = error

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,7 @@ from typing import TypeVar
from typing import Union from typing import Union
import attr import attr
import py import py
# fmt: off # fmt: off

View File

@ -6,5 +6,5 @@ import sys
import _pytest._py.error as error import _pytest._py.error as error
import _pytest._py.path as path import _pytest._py.path as path
sys.modules['py.error'] = error sys.modules["py.error"] = error
sys.modules['py.path'] = path sys.modules["py.path"] = path