Skip to content

Commit

Permalink
enforcing single quotes (#612)
Browse files Browse the repository at this point in the history
* enforcing single quotes

* update history
  • Loading branch information
samuelcolvin committed Jun 21, 2019
1 parent 6233554 commit 461b852
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ History

v0.30 (unreleased)
..................
* enforce single quotes in code, #612 by @samuelcolvin
* fix infinite recursion with dataclass inheritance and ``__post_init__``, #606 by @Hanaasagi

v0.29 (2019-06-19)
Expand Down
4 changes: 2 additions & 2 deletions pydantic/class_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def validator(
raise ConfigError('validator with no fields specified')
elif isinstance(fields[0], FunctionType):
raise ConfigError(
"validators should be used with fields and keyword arguments, not bare. "
"validators should be used with fields and keyword arguments, not bare. " # noqa: Q000
"E.g. usage should be `@validator('<field_name>', ...)`"
)

Expand Down Expand Up @@ -94,7 +94,7 @@ def check_for_unused(self) -> None:
if unused_validators:
fn = ', '.join(unused_validators)
raise ConfigError(
f"Validators defined with incorrect fields: {fn} "
f"Validators defined with incorrect fields: {fn} " # noqa: Q000
f"(use check_fields=False if you're inheriting from the model and intended this)"
)

Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ filterwarnings = error
[flake8]
max-line-length = 120
max-complexity = 14
inline-quotes = '
multiline-quotes = """
[bdist_wheel]
python-tag = py36.py37.py38
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ black==19.3b0
coverage==4.5.3
Cython==0.29.9;sys_platform!='win32'
flake8==3.7.7
flake8-quotes==2.0.1
isort==4.3.20
mypy==0.701
pycodestyle==2.5.0
Expand Down
6 changes: 3 additions & 3 deletions tests/test_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def my_abstract_property(self, val):

with pytest.raises(TypeError) as excinfo:
Model(some_field='some_value')
assert (
str(excinfo.value) == "Can't instantiate abstract class Model with abstract methods"
" my_abstract_classmethod, my_abstract_method, my_abstract_property, my_abstract_staticmethod"
assert str(excinfo.value) == (
"Can't instantiate abstract class Model with abstract methods "
"my_abstract_classmethod, my_abstract_method, my_abstract_property, my_abstract_staticmethod" # noqa: Q000
)
4 changes: 2 additions & 2 deletions tests/test_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class Model(BaseModel):
a: bytes
b: str

content_bytes = b"x" * (2 ** 16 + 1)
content_str = "x" * (2 ** 16 + 1)
content_bytes = b'x' * (2 ** 16 + 1)
content_str = 'x' * (2 ** 16 + 1)
m = Model(a=content_bytes, b=content_str)
assert m.a == content_bytes
assert m.b == content_str
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ def __post_init__(self, number):
derived = DerivedWithInitVar(1)
assert derived.plusone == 2
with pytest.raises(TypeError):
DerivedWithInitVar("Not A Number")
DerivedWithInitVar('Not A Number')


def test_classvar():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_edge_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def test_invalid_type():
class Model(BaseModel):
x: 43 = 123

assert "error checking inheritance of 43 (type: int)" in str(exc_info)
assert 'error checking inheritance of 43 (type: int)' in str(exc_info)


class CustomStr(str):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,11 @@ class Data(BaseModel):

success1 = Result[Data, Error](data=[Data(number=1, text='a')], positive_number=1)
assert success1.dict() == {'data': [{'number': 1, 'text': 'a'}], 'error': None, 'positive_number': 1}
assert str(success1) == 'Result[Data, Error] data=[<Data number=1 text=\'a\'>] error=None positive_number=1'
assert str(success1) == "Result[Data, Error] data=[<Data number=1 text='a'>] error=None positive_number=1"

success2 = Result[Data, Error](error=Error(message='error'), positive_number=1)
assert success2.dict() == {'data': None, 'error': {'message': 'error'}, 'positive_number': 1}
assert str(success2) == 'Result[Data, Error] data=None error=<Error message=\'error\'> positive_number=1'
assert str(success2) == "Result[Data, Error] data=None error=<Error message='error'> positive_number=1"
with pytest.raises(ValidationError) as exc_info:
Result[Data, Error](error=Error(message='error'), positive_number=-1)
assert exc_info.value.errors() == [{'loc': ('positive_number',), 'msg': '', 'type': 'value_error'}]
Expand Down
12 changes: 6 additions & 6 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_enum_fails():


def test_int_enum_successful_for_str_int():
m = CookingModel(tool="2")
m = CookingModel(tool='2')
assert m.tool == ToolEnum.wrench
assert repr(m.tool) == '<ToolEnum.wrench: 2>'

Expand Down Expand Up @@ -923,7 +923,7 @@ class Model(BaseModel):
Model(v=123)

with pytest.raises(ValidationError):
Model(v=b"foobar")
Model(v=b'foobar')


def test_strict_bool():
Expand All @@ -937,10 +937,10 @@ class Model(BaseModel):
Model(v=1)

with pytest.raises(ValidationError):
Model(v="1")
Model(v='1')

with pytest.raises(ValidationError):
Model(v=b"1")
Model(v=b'1')


def test_uuid_error():
Expand Down Expand Up @@ -1471,7 +1471,7 @@ class JsonModel(BaseModel):
json_obj: Json

obj = '{"a": 1, "b": [2, 3]}'
assert JsonModel(json_obj=obj).dict() == {'json_obj': {"a": 1, "b": [2, 3]}}
assert JsonModel(json_obj=obj).dict() == {'json_obj': {'a': 1, 'b': [2, 3]}}


def test_invalid_simple_json():
Expand All @@ -1489,7 +1489,7 @@ class JsonModel(BaseModel):
json_obj: Json

obj = b'{"a": 1, "b": [2, 3]}'
assert JsonModel(json_obj=obj).dict() == {'json_obj': {"a": 1, "b": [2, 3]}}
assert JsonModel(json_obj=obj).dict() == {'json_obj': {'a': 1, 'b': [2, 3]}}


def test_valid_detailed_json():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def check_b(cls, v):
return v

assert str(exc_info.value) == (
"Validators defined with incorrect fields: check_b "
"Validators defined with incorrect fields: check_b " # noqa: Q000
"(use check_fields=False if you're inheriting from the model and intended this)"
)

Expand Down

0 comments on commit 461b852

Please sign in to comment.