Skip to content

Commit 5712edf

Browse files
authored
Adopt ruff formatter instead of black (ready for review) (#1051)
1 parent d3416f7 commit 5712edf

File tree

13 files changed

+32
-39
lines changed

13 files changed

+32
-39
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315
version: '3.1.32'
316316
actions-cache-folder: emsdk-cache
317317

318-
- run: pip install 'maturin>=1,<2' 'black>=22.3.0,<23' typing_extensions
318+
- run: pip install 'maturin>=1,<2' 'ruff==0.1.3' typing_extensions
319319

320320
- name: build wheels
321321
run: make build-wasm
@@ -442,7 +442,7 @@ jobs:
442442
python-version: '3.11'
443443
architecture: ${{ matrix.python-architecture || 'x64' }}
444444

445-
- run: pip install -U twine 'black>=22.3.0,<23' typing_extensions
445+
- run: pip install -U twine 'ruff==0.1.3' typing_extensions
446446

447447
# generate self-schema now, so we don't have to do so inside docker in maturin build
448448
- run: python generate_self_schema.py
@@ -501,7 +501,7 @@ jobs:
501501
with:
502502
components: llvm-tools
503503

504-
- run: pip install -U 'black>=22.3.0,<23' typing_extensions
504+
- run: pip install -U 'ruff==0.1.3' typing_extensions
505505

506506
# generate self-schema now, so we don't have to do so inside docker in maturin build
507507
- run: python generate_self_schema.py

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DEFAULT_GOAL := all
2-
black = black python/pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
3-
ruff = ruff python/pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
2+
sources = python/pydantic_core tests generate_self_schema.py wasm-preview/run_tests.py
3+
44
mypy-stubtest = python -m mypy.stubtest pydantic_core._pydantic_core --allowlist .mypy-stubtest-allowlist
55

66
# using pip install cargo (via maturin via pip) doesn't get the tty handle
@@ -90,14 +90,14 @@ build-wasm:
9090

9191
.PHONY: format
9292
format:
93-
$(black)
94-
$(ruff) --fix --exit-zero
93+
ruff --fix $(sources)
94+
ruff format $(sources)
9595
cargo fmt
9696

9797
.PHONY: lint-python
9898
lint-python:
99-
$(ruff)
100-
$(black) --check --diff
99+
ruff $(sources)
100+
ruff format --check $(sources)
101101
$(mypy-stubtest)
102102
griffe dump -f -d google -LWARNING -o/dev/null python/pydantic_core
103103

pyproject.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,15 @@ features = ["pyo3/extension-module"]
5757
line-length = 120
5858
extend-select = ['Q', 'RUF100', 'C90', 'I']
5959
extend-ignore = [
60-
'E501', # ignore line too long and let black handle it
6160
'E721', # using type() instead of isinstance() - we use this in tests
6261
]
6362
flake8-quotes = {inline-quotes = 'single', multiline-quotes = 'double'}
6463
mccabe = { max-complexity = 13 }
6564
isort = { known-first-party = ['pydantic_core', 'tests'] }
6665

66+
[tool.ruff.format]
67+
quote-style = 'single'
68+
6769
[tool.pytest.ini_options]
6870
testpaths = 'tests'
6971
log_format = '%(name)s %(levelname)s: %(message)s'
@@ -97,13 +99,6 @@ exclude_lines = [
9799
'@overload',
98100
]
99101

100-
[tool.black]
101-
color = true
102-
line-length = 120
103-
target-version = ['py37', 'py38', 'py39', 'py310']
104-
skip-string-normalization = true
105-
skip-magic-trailing-comma = true
106-
107102
# configuring https://github.com/pydantic/hooky
108103
[tool.hooky]
109104
assignees = ['samuelcolvin', 'adriangb', 'dmontagu', 'davidhewitt', 'lig']

python/pydantic_core/_pydantic_core.pyi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,6 @@ def list_all_errors() -> list[ErrorTypeInfo]:
847847
Returns:
848848
A list of `ErrorTypeInfo` typed dicts.
849849
"""
850-
851850
@final
852851
class TzInfo(datetime.tzinfo):
853852
def tzname(self, _dt: datetime.datetime | None) -> str | None: ...

tests/requirements-linting.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
black==23.10.1
2-
griffe==0.36.9
3-
pyright==1.1.334
1+
griffe==0.36.7
2+
pyright==1.1.332
43
ruff==0.1.3
54
mypy==1.6.1

tests/serializers/test_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def append_args(value, info):
228228
'exclude_defaults=False, exclude_none=False, round_trip=False)'
229229
)
230230
assert s.to_json(123) == (
231-
b'"123 info=SerializationInfo(include=None, exclude=None, mode=\'json\', by_alias=True, exclude_unset=False, '
231+
b"\"123 info=SerializationInfo(include=None, exclude=None, mode='json', by_alias=True, exclude_unset=False, "
232232
b'exclude_defaults=False, exclude_none=False, round_trip=False)"'
233233
)
234234

tests/test_errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,9 +1050,9 @@ def test_loc_with_dots(pydantic_version):
10501050
]
10511051
# insert_assert(str(exc_info.value))
10521052
assert str(exc_info.value) == (
1053-
"1 validation error for typed-dict\n"
1054-
"`foo.bar`.0\n"
1055-
" Input should be a valid integer, unable to parse string as an integer "
1053+
'1 validation error for typed-dict\n'
1054+
'`foo.bar`.0\n'
1055+
' Input should be a valid integer, unable to parse string as an integer '
10561056
"[type=int_parsing, input_value='x', input_type=str]\n"
10571057
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/int_parsing'
10581058
)

tests/validators/test_arguments.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,11 @@ def test_error_display(pydantic_version):
10091009
]
10101010
# insert_assert(str(exc_info.value))
10111011
assert str(exc_info.value) == (
1012-
"1 validation error for arguments\n"
1013-
"b\n"
1014-
" Missing required argument [type=missing_argument, "
1012+
'1 validation error for arguments\n'
1013+
'b\n'
1014+
' Missing required argument [type=missing_argument, '
10151015
"input_value=ArgsKwargs((), {'a': 1}), input_type=ArgsKwargs]\n"
1016-
f" For further information visit https://errors.pydantic.dev/{pydantic_version}/v/missing_argument"
1016+
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/missing_argument'
10171017
)
10181018
# insert_assert(exc_info.value.json(include_url=False))
10191019
assert exc_info.value.json(include_url=False) == (

tests/validators/test_bool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_bool_error(pydantic_version):
6363
'1 validation error for bool\n'
6464
' Input should be a valid boolean, '
6565
"unable to interpret input [type=bool_parsing, input_value='wrong', input_type=str]\n"
66-
f" For further information visit https://errors.pydantic.dev/{pydantic_version}/v/bool_parsing"
66+
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/bool_parsing'
6767
)
6868
assert exc_info.value.errors(include_url=False) == [
6969
{

tests/validators/test_int.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,10 +357,10 @@ def test_too_long(pydantic_version):
357357
]
358358
# insert_assert(repr(exc_info.value))
359359
assert repr(exc_info.value) == (
360-
"1 validation error for int\n"
361-
" Unable to parse input string as an integer, exceeded maximum size "
360+
'1 validation error for int\n'
361+
' Unable to parse input string as an integer, exceeded maximum size '
362362
"[type=int_parsing_size, input_value='111111111111111111111111...11111111111111111111111', input_type=str]\n"
363-
f" For further information visit https://errors.pydantic.dev/{pydantic_version}/v/int_parsing_size"
363+
f' For further information visit https://errors.pydantic.dev/{pydantic_version}/v/int_parsing_size'
364364
)
365365

366366

0 commit comments

Comments
 (0)