Skip to content

Commit

Permalink
Ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ahankinson committed Sep 12, 2024
1 parent e95ab2e commit ea460bf
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 23 deletions.
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,36 @@ black = "^23.3.0"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.ruff.lint]
select = [
# pycodestyle
"E",
# pycodestyle warnings
"W",
# Pyflakes
"F",
# pyupgrade
## Flake8 plugins
"UP",
# flake8-bugbear
"B",
# flake8-comprehensions
"C",
# flake8-django
"DJ",
# flake8-bandit
"S",
# flake8-simplify
"SIM",
# isort
"I",
]

ignore = [
# Ignore Pycodestyle line-length warnings, (mainly long comments).
"E501",
# Ignore McCabe complexity (for now).
"C901",
]
2 changes: 1 addition & 1 deletion tests/obj.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Obj(object):
class Obj:
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
10 changes: 6 additions & 4 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .obj import Obj
from ypres.fields import Field, MethodField, BoolField, IntField, FloatField, StrField
import unittest

from ypres.fields import BoolField, Field, FloatField, IntField, MethodField, StrField

from .obj import Obj


class TestFields(unittest.TestCase):
def test_to_value_noop(self):
Expand All @@ -10,7 +12,7 @@ def test_to_value_noop(self):
self.assertEqual(Field().to_value(None), None)

def test_as_getter_none(self):
self.assertEqual(Field().as_getter(None, None), None)
self.assertEqual(Field().as_getter(None, None), None) # noqa

def test_is_to_value_overridden(self):
class TransField(Field):
Expand Down Expand Up @@ -62,7 +64,7 @@ def test_float_field(self):
self.assertEqual(field.to_value("5.5"), 5.5)

def test_method_field(self):
class FakeSerializer(object):
class FakeSerializer:
def get_a(self, obj):
return obj.a

Expand Down
14 changes: 8 additions & 6 deletions tests/test_serializer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from .obj import Obj
from ypres.fields import Field, MethodField, IntField, FloatField, StrField, BoolField
from ypres.serializer import Serializer, DictSerializer
import unittest

from ypres.fields import BoolField, Field, FloatField, IntField, MethodField, StrField
from ypres.serializer import DictSerializer, Serializer

from .obj import Obj


class TestSerializer(unittest.TestCase):
def test_simple(self):
Expand Down Expand Up @@ -169,7 +171,7 @@ class ASerializer(Serializer):

o = Obj(a=None)
with self.assertRaises(TypeError):
ASerializer(o).data
ASerializer(o).data # noqa

def test_optional_field_dictserializer(self):
class ASerializer(DictSerializer):
Expand All @@ -188,7 +190,7 @@ class ASerializer(DictSerializer):
self.assertIsNone(data.get("a"))

with self.assertRaises(KeyError):
ASerializer({}).data
ASerializer({}).data # noqa

def test_optional_field(self):
class ASerializer(Serializer):
Expand All @@ -211,7 +213,7 @@ class ASerializer(Serializer):

o = Obj()
with self.assertRaises(AttributeError):
ASerializer(o).data
ASerializer(o).data # noqa

def test_optional_methodfield(self):
class ASerializer(Serializer):
Expand Down
12 changes: 6 additions & 6 deletions ypres/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from ypres.fields import (
Field,
BoolField,
IntField,
Field,
FloatField,
IntField,
MethodField,
StrField,
StaticField,
StrField,
)
from ypres.serializer import (
Serializer,
DictSerializer,
AsyncSerializer,
AsyncDictSerializer,
AsyncSerializer,
DictSerializer,
Serializer,
)

__version__ = "1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion ypres/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import types
from typing import Optional, Any
from typing import Any, Optional


class Field:
Expand Down
10 changes: 5 additions & 5 deletions ypres/serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
import operator
from typing import Callable, Optional, Union, Any, Mapping
from typing import Any, Callable, Mapping, Optional, Union

from ypres.fields import Field

Expand Down Expand Up @@ -60,10 +60,10 @@ def __new__(mcs, name, bases, attrs: dict):
for attr_name, field in attrs.items():
if isinstance(field, Field):
direct_fields[attr_name] = field
for k in direct_fields.keys():
for k in direct_fields:
del attrs[k]

real_cls = super(SerializerMeta, mcs).__new__(mcs, name, bases, attrs)
real_cls = super().__new__(mcs, name, bases, attrs)

field_map = mcs._get_fields(direct_fields, real_cls)
compiled_fields = mcs._compile_fields(field_map, real_cls)
Expand Down Expand Up @@ -110,7 +110,7 @@ def __init__(
many: bool = False,
context: Optional[dict] = None,
emit_none: bool = False,
**kwargs
**kwargs,
):
super().__init__(**kwargs)
self.instance: Any = instance
Expand Down Expand Up @@ -221,7 +221,7 @@ def __init__(
many: bool = False,
context: Optional[dict] = None,
emit_none: bool = False,
**kwargs
**kwargs,
):
super().__init__(**kwargs)
self.instance: Optional[Any] = instance
Expand Down

0 comments on commit ea460bf

Please sign in to comment.