Skip to content

Commit

Permalink
Fix more with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Dec 29, 2023
1 parent 364d56d commit 50b2506
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
4 changes: 2 additions & 2 deletions auto_editor/lang/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ def dump(
file.write(f'"{normalize_string(data)}"')
elif isinstance(data, FileInfo):
file.write(f'"{normalize_string(f"{data.path}")}"')
elif isinstance(data, (int, float)):
elif isinstance(data, int | float):
file.write(f"{data}")
elif isinstance(data, (list, tuple)):
elif isinstance(data, list | tuple):
file.write("[")
if indent is not None:
level += indent
Expand Down
4 changes: 2 additions & 2 deletions auto_editor/lang/palet.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def __str__(self) -> str:
)
is_sequence = Contract(
"sequence?",
lambda v: type(v) in (str, range, Quoted) or isinstance(v, (list, np.ndarray)),
lambda v: type(v) in (str, range, Quoted) or isinstance(v, list | np.ndarray),
)
is_boolarr = Contract(
"bool-array?",
Expand Down Expand Up @@ -685,7 +685,7 @@ def palet_map(proc: Proc, seq: Any) -> Any:
return str(map(proc, seq))
if type(seq) is Quoted:
return Quoted(tuple(map(proc, seq.val)))
if isinstance(seq, (list, range)):
if isinstance(seq, list | range):
return list(map(proc, seq))
return proc(seq)

Expand Down
2 changes: 1 addition & 1 deletion auto_editor/lib/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def is_contract(c: object) -> bool:
"threshold?",
lambda v: type(v) in (int, float) and v >= 0 and v <= 1, # type: ignore
)
is_proc = Contract("procedure?", lambda v: isinstance(v, (Proc, Contract)))
is_proc = Contract("procedure?", lambda v: isinstance(v, Proc | Contract))


def andc(*cs: object) -> Proc:
Expand Down
3 changes: 2 additions & 1 deletion auto_editor/timeline.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from collections.abc import Iterator
from dataclasses import dataclass
from fractions import Fraction
from typing import Any, Iterator
from typing import Any

from auto_editor.ffwrapper import FileInfo
from auto_editor.lib.contracts import *
Expand Down
2 changes: 1 addition & 1 deletion auto_editor/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _comma_coerce(name: str, val: str, num_args: int) -> list[str]:


def _split_num_str(val: str | float) -> tuple[float, str]:
if isinstance(val, (float, int)):
if isinstance(val, float | int):
return val, ""

index = 0
Expand Down
5 changes: 3 additions & 2 deletions auto_editor/vanparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from auto_editor.utils.types import CoerceError

if TYPE_CHECKING:
from typing import Any, Callable, Literal, TypeVar
from collections.abc import Callable
from typing import Any, Literal, TypeVar

T = TypeVar("T")
Nargs = int | Literal["*"]
Expand Down Expand Up @@ -136,7 +137,7 @@ def print_option_help(program_name: str | None, ns_obj: T, option: Options) -> N
except AttributeError:
pass

if default is not None and isinstance(default, (int, float, str)):
if default is not None and isinstance(default, int | float | str):
text.write(f" default: {default}\n")

if option.choices is not None:
Expand Down
29 changes: 27 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,30 @@ aeinfo = "auto_editor.subcommands.info:main"
aesubdump = "auto_editor.subcommands.subdump:main"
aelevels = "auto_editor.subcommands.levels:main"

[tool.isort]
profile = "black"
[tool.mypy]
warn_unused_ignores = true
warn_redundant_casts = true
extra_checks = true
disallow_untyped_calls = true
disallow_untyped_decorators = true
strict_optional = true
strict_equality = true
python_version = "3.10"

[tool.ruff]
select = [
"UP", # pyupgrade
"E", # pycodestyle
"F", # Pyflakes
"W", # pycodestyle
"I", # isort
"C401", # flake8-comprehensions: unnecessary-generator-set
"C402", # flake8-comprehensions: unnecessary-generator-dict
"C403", # flake8-comprehensions: unnecessary-list-comprehension-set
"C404", # flake8-comprehensions: unnecessary-list-comprehension-dict
"C405", # flake8-comprehensions: unnecessary-literal-set
]
target-version = "py310"

[tool.ruff.lint]
ignore = ["E501", "E712", "E721", "F403", "F405"]

0 comments on commit 50b2506

Please sign in to comment.