Skip to content

Commit ffca061

Browse files
committed
Upgrade ruff 0.5.5 -> 0.11.11
Run `ruff check . --fix` Run `ruff format .` Move test-specifc `ruff.toml` to `per-file-ignores` Sort test imports Import `Literal` from `typing` Force `from __future__ import annotations` import Rewrite `dict()` as literal (2x faster) Disallow function calls in default arguments Be intentional about exception context Upgrade all (compatible) generics to built-in types Sort `__all__` blocks Enable `RUF` ruleset Prefer tuple unpacking over concatenation Forbid implicit optional No explicit string concatenation Remove unnecessary `pass` statements Remove unnecessary parantheses on raised exceptions Disallow relative imports from parent modules Remove unused import aliases Add lint rule comments Revert "Disallow function calls in default arguments" This reverts commit 12a0a6a. Fix some stragglers Updated ruff version in workflow Lint `data/` dirs rebase fixes sentinel pattern for function calls in default arguments rebase fixes
1 parent ee3c189 commit ffca061

File tree

367 files changed

+5450
-4739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

367 files changed

+5450
-4739
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
fetch-depth: 1
123123
- uses: astral-sh/ruff-action@v3
124124
with:
125-
version: 0.5.5
125+
version: 0.11.11
126126
- name: Run ruff format
127127
run: ruff format --check --diff
128128
- name: Run ruff check

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: "v0.5.5"
3+
rev: "v0.11.11"
44
hooks:
55
- id: ruff
66
args: [ --fix ]

docs/_ext/custom-meta.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24

35

docs/_ext/custom-robots.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import os
24

35

docs/_ext/custom-sitemap.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import re
24
import xml.etree.ElementTree as ET
35

docs/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# relative to the documentation root, use os.path.abspath to make it
1818
# absolute, like shown here.
1919
#
20+
from __future__ import annotations
21+
2022
import datetime
2123
import logging
2224
import os

docs/generate_doc.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Generate documentation for Material Library (Python)
2+
from __future__ import annotations
23

34
import numpy as np
45

@@ -24,8 +25,7 @@ def generate_material_library_doc():
2425
def num2str(num):
2526
if np.isinf(num):
2627
return " "
27-
else:
28-
return str(round(num, 2))
28+
return str(round(num, 2))
2929

3030
with open(fname, "w") as f:
3131
# Write file header
@@ -238,8 +238,7 @@ def generate_rf_material_library_doc():
238238
def num2str(num):
239239
if np.isinf(num):
240240
return " "
241-
else:
242-
return str(round(num, 2))
241+
return str(round(num, 2))
243242

244243
with open(fname, "w") as f:
245244
# Write file header

poetry.lock

Lines changed: 66 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ joblib = "*"
5252
### Optional dependencies ###
5353
# development core
5454
bump-my-version = { version = "*", optional = true }
55-
ruff = { version = "0.5.5", optional = true }
55+
ruff = { version = "0.11.11", optional = true }
5656
coverage = { version = "*", optional = true }
5757
dill = { version = "*", optional = true }
5858
ipython = { version = "*", optional = true }
@@ -245,31 +245,48 @@ line-length = 100
245245
extend-exclude = ["docs/faq/", "docs/notebooks/"]
246246

247247
[tool.ruff.lint]
248-
typing-modules = [
249-
"tidy3d.components.types",
250-
] # without this Literal["something fails"]
251-
select = [
252-
"I", # isort
248+
extend-select = [
253249
"E", # pycodestyle errors
254-
"W", # pycodestyle warnings
255250
"F", # pyflakes
256-
"C", # flake8-comprehensions
257-
"B", # flake8-bugbear
258-
"UP",
259-
"NPY201", # numpy 2.* compatibility check
251+
"B", # bugbear
252+
"I", # isort
253+
"UP", # pyupgrade
254+
"W", # pycodestyle
255+
"C4", # flake8-comprehensions
256+
"NPY", # numpy-specific rules
257+
"RUF", # ruff builtins
258+
"ISC", # implicit string concatenation
259+
"PIE", # flake8-pie
260+
"RSE", # unnecessary parantheses on raised exceptions
261+
"TID", # no relative imports from parent modules
262+
"PLE", # pylint errors
263+
"PLC", # pylint conventions
264+
]
265+
extend-ignore = [
266+
"RUF001", # ambiguous unicode characters
267+
"RUF002", # ambiguous unicode characters
268+
"RUF003", # ambiguous unicode characters
269+
"RUF012", # type hints for mutable defaults
270+
"RUF015", # next(iter(...)) instead of list(...)[0]
271+
"E501", # line too long
272+
"B905", # `zip()` without an explicit `strict=` parameter
273+
"UP007", # TODO: Remove once Python >= 3.10
274+
"NPY002", # TODO: Revisit RNG handling
260275
]
261-
ignore = [
262-
"E501",
263-
"B008", # do not perform function calls in argument defaults
264-
"C901", # too complex
265-
"UP007", # use x | y instead of union[x,y] (does not work)
266-
"B905", # `zip()` without an explicit `strict=` parameter
267-
"C408", # C408 Unnecessary `dict` call (rewrite as a literal)
268-
"B904",
269-
"B028", # stacklevel
270-
"UP006", # typy annotation with Tuple[float] messes up pydantic
271-
"UP038", # TODO decide what to do here
272-
"UP035", # TODO decide what to do here
276+
277+
[tool.ruff.lint.isort]
278+
required-imports = ["from __future__ import annotations"]
279+
280+
[tool.ruff.lint.per-file-ignores]
281+
"tests/**/*" = [
282+
"B015", # useless comparison
283+
"B018", # useless expression
284+
"E402", # module-level import not at top of file
285+
"E731", # lambda assignment
286+
"F841", # unused local variable
287+
"S101", # asserts allowed in tests
288+
"NPY201", # numpy 2.* compatibility check
289+
"TID252", # allow relative imports in tests
273290
]
274291

275292
[tool.pytest.ini_options]

scripts/benchmark_import.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
14
def test_import():
25
import subprocess
36
import time

0 commit comments

Comments
 (0)