[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.
"""
import errno
import os
import sys
from types import ModuleType
import sys, os, errno
class Error(EnvironmentError):
def __repr__(self):
return "%s.%s %r: %s " %(self.__class__.__module__,
self.__class__.__name__,
self.__class__.__doc__,
" ".join(map(str, self.args)),
#repr(self.args)
)
return "{}.{} {!r}: {} ".format(
self.__class__.__module__,
self.__class__.__name__,
self.__class__.__doc__,
" ".join(map(str, self.args)),
# repr(self.args)
)
def __str__(self):
s = "[%s]: %s" %(self.__class__.__doc__,
" ".join(map(str, self.args)),
)
s = "[{}]: {}".format(
self.__class__.__doc__,
" ".join(map(str, self.args)),
)
return s
_winerrnomap = {
2: errno.ENOENT,
3: errno.ENOENT,
17: errno.EEXIST,
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,
20: errno.ENOTDIR,
267: errno.ENOTDIR,
5: errno.EACCES, # anything better?
}
class ErrorMaker(ModuleType):
""" lazily provides Exception classes for each possible POSIX errno
(as defined per the 'errno' module). All such instances
subclass EnvironmentError.
"""lazily provides Exception classes for each possible POSIX errno
(as defined per the 'errno' module). All such instances
subclass EnvironmentError.
"""
Error = Error
_errno2class = {}
@ -52,23 +60,25 @@ class ErrorMaker(ModuleType):
try:
return self._errno2class[eno]
except KeyError:
clsname = errno.errorcode.get(eno, "UnknownErrno%d" %(eno,))
errorcls = type(Error)(clsname, (Error,),
{'__module__':'py.error',
'__doc__': os.strerror(eno)})
clsname = errno.errorcode.get(eno, "UnknownErrno%d" % (eno,))
errorcls = type(Error)(
clsname,
(Error,),
{"__module__": "py.error", "__doc__": os.strerror(eno)},
)
self._errno2class[eno] = errorcls
return errorcls
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
try:
return func(*args, **kwargs)
except self.Error:
raise
except (OSError, EnvironmentError):
except OSError:
cls, value, tb = sys.exc_info()
if not hasattr(value, 'errno'):
if not hasattr(value, "errno"):
raise
__tracebackhide__ = False
errno = value.errno
@ -83,9 +93,9 @@ class ErrorMaker(ModuleType):
cls = self._geterrnoclass(_winerrnomap[errno])
except KeyError:
raise value
raise cls("%s%r" % (func.__name__, args))
raise cls(f"{func.__name__}{args!r}")
__tracebackhide__ = True
error = ErrorMaker('_pytest._py.error')
error = ErrorMaker("_pytest._py.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
import attr
import py
# fmt: off

View File

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