Skip to content

Commit

Permalink
First batch of ruff/black autorefactors/format.
Browse files Browse the repository at this point in the history
  • Loading branch information
ionelmc committed Dec 13, 2023
1 parent bd2c628 commit ff7459e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/lazy_object_proxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
except ImportError:
__version__ = '1.9.0'

__all__ = ("Proxy",)
__all__ = ('Proxy',)
2 changes: 1 addition & 1 deletion src/lazy_object_proxy/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

def with_metaclass(meta, *bases):
"""Create a base class with a metaclass."""
return meta("NewBase", bases, {})
return meta('NewBase', bases, {})
4 changes: 2 additions & 2 deletions src/lazy_object_proxy/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def proxy_wrapper(self, *args):
return proxy_wrapper


class _ProxyMethods(object):
class _ProxyMethods:
# We use properties to override the values of __module__ and
# __doc__. If we add these in ObjectProxy, the derived class
# __dict__ will still be setup to have string variants of these
Expand Down Expand Up @@ -95,7 +95,7 @@ def __repr__(self, __getattr__=object.__getattribute__):
type(self).__name__, id(self), self.__wrapped__, id(self.__wrapped__), self.__factory__
)
else:
return '<{} at 0x{:x} with factory {!r}>'.format(type(self).__name__, id(self), self.__factory__)
return f'<{type(self).__name__} at 0x{id(self):x} with factory {self.__factory__!r}>'

def __fspath__(self):
wrapped = self.__wrapped__
Expand Down
12 changes: 5 additions & 7 deletions src/lazy_object_proxy/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .utils import identity


class _ProxyMethods(object):
class _ProxyMethods:
# We use properties to override the values of __module__ and
# __doc__. If we add these in ObjectProxy, the derived class
# __dict__ will still be setup to have string variants of these
Expand Down Expand Up @@ -124,8 +124,8 @@ def __name__(self, value):
def __class__(self):
return self.__wrapped__.__class__

@__class__.setter # noqa: F811
def __class__(self, value): # noqa: F811
@__class__.setter
def __class__(self, value):
self.__wrapped__.__class__ = value

@property
Expand All @@ -149,11 +149,9 @@ def __repr__(self, __getattr__=object.__getattribute__):
try:
target = __getattr__(self, '__target__')
except AttributeError:
return '<{} at 0x{:x} with factory {!r}>'.format(type(self).__name__, id(self), self.__factory__)
return f'<{type(self).__name__} at 0x{id(self):x} with factory {self.__factory__!r}>'
else:
return '<{} at 0x{:x} wrapping {!r} at 0x{:x} with factory {!r}>'.format(
type(self).__name__, id(self), target, id(target), self.__factory__
)
return f'<{type(self).__name__} at 0x{id(self):x} wrapping {target!r} at 0x{id(target):x} with factory {self.__factory__!r}>'

def __fspath__(self):
wrapped = self.__wrapped__
Expand Down
2 changes: 1 addition & 1 deletion src/lazy_object_proxy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def identity(obj):
return obj


class cached_property(object):
class cached_property:
def __init__(self, func):
self.func = func

Expand Down
36 changes: 18 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
PYPY = '__pypy__' in sys.builtin_module_names


@pytest.fixture(scope="session")
@pytest.fixture(scope='session')
def lop_loader():
def load_implementation(name):
class FakeModule:
subclass = False
kind = name
if name == "slots":
if name == 'slots':
from lazy_object_proxy.slots import Proxy
elif name == "simple":
elif name == 'simple':
from lazy_object_proxy.simple import Proxy
elif name == "cext":
elif name == 'cext':
try:
from lazy_object_proxy.cext import Proxy
except ImportError:
if PYPY:
pytest.skip(reason="C Extension not available.")
pytest.skip(reason='C Extension not available.')
else:
raise
elif name == "objproxies":
Proxy = pytest.importorskip("objproxies").LazyProxy
elif name == "django":
Proxy = pytest.importorskip("django.utils.functional").SimpleLazyObject
elif name == 'objproxies':
Proxy = pytest.importorskip('objproxies').LazyProxy
elif name == 'django':
Proxy = pytest.importorskip('django.utils.functional').SimpleLazyObject
else:
raise RuntimeError("Unsupported param: %r." % name)
raise RuntimeError('Unsupported param: %r.' % name)

Proxy

Expand All @@ -38,32 +38,32 @@ class FakeModule:


@pytest.fixture(
scope="session",
scope='session',
params=[
"slots",
"cext",
"simple",
'slots',
'cext',
'simple',
# "external-django", "external-objproxies"
],
)
def lop_implementation(request, lop_loader):
return lop_loader(request.param)


@pytest.fixture(scope="session", params=[True, False], ids=['subclassed', 'normal'])
@pytest.fixture(scope='session', params=[True, False], ids=['subclassed', 'normal'])
def lop_subclass(request, lop_implementation):
if request.param:

class submod(lop_implementation):
subclass = True
Proxy = type("SubclassOf_" + lop_implementation.Proxy.__name__, (lop_implementation.Proxy,), {})
Proxy = type('SubclassOf_' + lop_implementation.Proxy.__name__, (lop_implementation.Proxy,), {})

return submod
else:
return lop_implementation


@pytest.fixture(scope="function")
@pytest.fixture(scope='function')
def lop(request, lop_subclass):
if request.node.get_closest_marker('xfail_subclass'):
request.applymarker(
Expand All @@ -72,6 +72,6 @@ def lop(request, lop_subclass):
)
)
if request.node.get_closest_marker('xfail_simple'):
request.applymarker(pytest.mark.xfail(reason="The lazy_object_proxy.simple.Proxy has some limitations."))
request.applymarker(pytest.mark.xfail(reason='The lazy_object_proxy.simple.Proxy has some limitations.'))

return lop_subclass
Loading

0 comments on commit ff7459e

Please sign in to comment.