Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ruff): Update to 0.9.0 #3766

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion altair/utils/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def set_inspect_mode_argument(
mode = "vega-lite"

if mode != "vega-lite":
msg = "mode must be 'vega-lite', " f"not '{mode}'"
msg = f"mode must be 'vega-lite', not '{mode}'"
raise ValueError(msg)

if mode == "vega-lite" and vegalite_version is None:
Expand Down
2 changes: 1 addition & 1 deletion altair/utils/schemapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from typing import Never, Self
else:
from typing_extensions import Never, Self
_OptionalModule: TypeAlias = "ModuleType | None"
_OptionalModule: TypeAlias = "ModuleType | None" # noqa: TC008

ValidationErrorList: TypeAlias = list[jsonschema.exceptions.ValidationError]
GroupedValidationErrors: TypeAlias = dict[str, ValidationErrorList]
Expand Down
10 changes: 4 additions & 6 deletions altair/vegalite/v5/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def __repr__(self) -> str:
args = f"{COND}{self.condition!r}".replace("\n", "\n ")
else:
conds = "\n ".join(f"{c!r}" for c in self.condition)
args = f"{COND}[\n " f"{conds}\n ]"
args = f"{COND}[\n {conds}\n ]"
return f"{name}({LB}\n {args}\n{RB})"


Expand Down Expand Up @@ -1166,9 +1166,7 @@ def __init__(

def __repr__(self) -> str:
return (
f"{type(self).__name__}(\n"
f" {self._conditions!r},\n {self._condition!r}\n"
")"
f"{type(self).__name__}(\n {self._conditions!r},\n {self._condition!r}\n)"
)

def then(self, statement: _StatementType, /, **kwds: Any) -> Then[_Conditions]:
Expand Down Expand Up @@ -3771,7 +3769,7 @@ def show(self) -> None:
def _set_resolve(self, **kwargs: Any): # noqa: ANN202
"""Copy the chart and update the resolve property with kwargs."""
if not hasattr(self, "resolve"):
msg = f"{self.__class__} object has no attribute " "'resolve'"
msg = f"{self.__class__} object has no attribute 'resolve'"
raise ValueError(msg)
copy = _top_schema_base(self).copy(deep=["resolve"])
if copy.resolve is Undefined:
Expand Down Expand Up @@ -4726,7 +4724,7 @@ def interactive(
"""
if not self.layer:
msg = "LayerChart: cannot call interactive() until a " "layer is defined"
msg = "LayerChart: cannot call interactive() until a layer is defined"
raise ValueError(msg)
copy = self.copy(deep=["layer"])
copy.layer[0] = copy.layer[0].interactive(
Expand Down
2 changes: 1 addition & 1 deletion altair/vegalite/v5/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# The display message when rendering fails
DEFAULT_DISPLAY: Final = f"""\
<VegaLite {VEGALITE_VERSION.split('.')[0]} object>
<VegaLite {VEGALITE_VERSION.split(".")[0]} object>
If you see this message, it means the renderer has not been properly enabled
for the frontend that you are using. For more information, see
Expand Down
284 changes: 93 additions & 191 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,193 +203,102 @@ publish-clean-build = [
]

[tool.ruff]
target-version = "py39"
line-length = 88
indent-width = 4
exclude = [
".git",
"build",
"__pycache__",
"build",
"tests/examples_arguments_syntax",
"tests/examples_methods_syntax",
]
indent-width = 4
line-length = 88
target-version = "py39"

[tool.ruff.lint]
# https://docs.astral.sh/ruff/preview/
preview = true

# https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes
extend-safe-fixes=[
# unnecessary-comprehension-in-call
"C419",
# literal-membership
"PLR6201",
# from __future__ import annotations #
# ---------------------------------- #
"UP006",
"UP007",
"UP008",
"TCH",
# assign exception msg to variable #
# -------------------------------- #
"EM101",
"EM102",
# trailing-whitespace
"W291",
# blank line contains whitespace
"W293",
# unsorted-dunder-all
"RUF022",
# pydocstyle #
# ---------- #
# fits-on-one-line
"D200",
# escape-sequence-in-docstring
"D301",
# ends-in-period
"D400",
# missing-return-type-special-method
"ANN204",
# unnecessary-dict-comprehension-for-iterable
"C420",
extend-safe-fixes = [ # https://docs.astral.sh/ruff/settings/#lint_extend-safe-fixes
"ANN204", # missing-return-type-special-method
"C419", # unnecessary-comprehension-in-call
"C420", # unnecessary-dict-comprehension-for-iterable
"D200", # fits-on-one-line
"D301", # escape-sequence-in-docstring
"D400", # ends-in-period
"EM101", # raw-string-in-exception
"EM102", # f-string-in-exception
"PLR6201", # literal-membership
"TC", # flake8-type-checking
"UP006", # non-pep585-annotation
"UP007", # non-pep604-annotation-union
"UP008", # super-call-with-parameters
"W291", # trailing-whitespace
"W293", # blank line contains whitespace
]

# https://docs.astral.sh/ruff/preview/#using-rules-that-are-in-preview
extend-select=[
# refurb
"FURB",
# pylint (preview) autofix #
# ------------------------ #
# unnecessary-dunder-call
"PLC2801",
# unnecessary-dict-index-lookup
"PLR1733",
# unnecessary-list-index-lookup
"PLR1736",
# literal-membership
"PLR6201",
# unspecified-encoding
"PLW1514",
extend-select = [ # https://docs.astral.sh/ruff/preview/#using-rules-that-are-in-preview
"FURB", # refurb
"PLC2801", # unnecessary-dunder-call
"PLR1733", # unnecessary-dict-index-lookup
"PLR1736", # unnecessary-list-index-lookup
"PLR6201", # literal-membership
"PLW1514", # unspecified-encoding
]
select = [
# flake8-bugbear
"B",
# flake8-comprehensions
"C4",
# pycodestyle-error
"E",
# flake8-errmsg
"EM",
# pyflakes
"F",
# flake8-future-annotations
"FA",
# flynt
"FLY",
# flake8-pie
"PIE",
# flake8-pytest-style
"PT",
# flake8-use-pathlib
"PTH",
# Ruff-specific rules
"RUF",
# flake8-simplify
"SIM",
# flake8-type-checking
"TCH",
# flake8-tidy-imports
"TID",
# pyupgrade
"UP",
# pycodestyle-warning
"W",
# pylint (stable) autofix #
# ----------------------- #
# iteration-over-set
"PLC0208",
# manual-from-import
"PLR0402",
# useless-return
"PLR1711",
# repeated-equality-comparison
"PLR1714",
# collapsible-else-if
"PLR5501",
# useless-else-on-loop
"PLW0120",
# subprocess-run-without-check
"PLW1510",
# nested-min-max
"PLW3301",
# pydocstyle #
# ---------- #
"D",
# multi-line-summary-second-line
"D213",
# numpy-specific-rules
"NPY",
# flake8-annotations
"ANN",
# unsorted-imports
"I001",
# complex-structure
"C901",
ignore = [
"ANN401", # any-type
"D100", # undocumented-public-module
"D101", # undocumented-public-class
"D102", # undocumented-public-method
"D103", # undocumented-public-function
"D104", # undocumented-public-package
"D105", # undocumented-magic-method
"D107", # undocumented-public-init
"D206", # indent-with-spaces
"D212", # multi-line-summary-first-line ((D213) is the opposite of this)
"D401", # non-imperative-mood
"D413", # missing-blank-line-after-last-section
"E501", # line-too-long (https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules)
"RUF012", # mutable-class-default
"RUF052", # used-dummy-variable
"SIM105", # suppressible-exception (https://github.com/vega/altair/pull/3431#discussion_r1629808660)
"W505", # doc-line-too-long
]
ignore = [
# Whitespace before ':'
"E203",
# Too many leading '#' for block comment
"E266",
# Line too long
"E501",
# zip() without an explicit strict= parameter set.
# python>=3.10 only
"B905",
# mutable-class-default
"RUF012",
# used-dummy-variable
"RUF052",
# suppressible-exception
# https://github.com/vega/altair/pull/3431#discussion_r1629808660
"SIM105",
# pydocstyle/ https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules #
# ------------------------------------------------------------------------- #
# undocumented-public-module
"D100",
# undocumented-public-class
"D101",
# undocumented-public-method
"D102",
# undocumented-public-function
"D103",
# undocumented-public-package
"D104",
# undocumented-magic-method
"D105",
# undocumented-public-init
"D107",
# indent-with-spaces
"D206",
# multi-line-summary-first-line ((D213) is the opposite of this)
"D212",
# Imperative mood
"D401",
# Blank line after last section
"D413",
# doc-line-too-long
"W505",
# Any as annotation
"ANN401"
mccabe.max-complexity = 10
preview = true # https://docs.astral.sh/ruff/preview/
pydocstyle.convention = "numpy" # https://docs.astral.sh/ruff/settings/#lintpydocstyle
select = [
"ANN", # flake8-annotations
"B", # flake8-bugbear
"C4", # flake8-comprehensions
"C901", # complex-structure
"D", # pydocstyle
"D213", # multi-line-summary-second-line
"E", # pycodestyle-error
"EM", # flake8-errmsg
"F", # pyflakes
"FA", # flake8-future-annotations
"FLY", # flynt
"I001", # unsorted-imports
"NPY", # numpy-specific-rules
"PIE", # flake8-pie
"PLC0208", # iteration-over-set
"PLR0402", # manual-from-import
"PLR1711", # useless-return
"PLR1714", # repeated-equality-comparison
"PLR5501", # collapsible-else-if
"PLW0120", # useless-else-on-loop
"PLW1510", # subprocess-run-without-check
"PLW3301", # nested-min-max
"PT", # flake8-pytest-style
"PTH", # flake8-use-pathlib
"RUF", # Ruff-specific rules
"SIM", # flake8-simplify
"TC", # flake8-type-checking
"TID", # flake8-tidy-imports
"UP", # pyupgrade
"W", # pycodestyle-warning
]
# https://docs.astral.sh/ruff/settings/#lintpydocstyle
pydocstyle={ convention="numpy" }
mccabe={ max-complexity=10 }

[tool.ruff.lint.isort]
classes = ["expr", "datum"]
classes = ["datum", "expr"]
extra-standard-library = ["typing_extensions"]
known-first-party=[
known-first-party = [
"altair_tiles",
"sphinxext_altair",
"vega_datasets",
Expand All @@ -400,37 +309,30 @@ split-on-trailing-comma = false

[tool.ruff.lint.flake8-tidy-imports.banned-api]
# https://docs.astral.sh/ruff/settings/#lint_flake8-tidy-imports_banned-api
"typing.Optional".msg = """
Use `Union[T, None]` instead.
`typing.Optional` is likely to be confused with `altair.typing.Optional`, \
which have a similar but different semantic meaning.
See https://github.com/vega/altair/pull/3449
"""
"narwhals.dependencies".msg = """
Import `dependencies` from `narwhals.stable.v1` instead.
"""
"narwhals.dtypes".msg = """
Import `dtypes` from `narwhals.stable.v1` instead.
"""
"narwhals.typing".msg = """
Import `typing` from `narwhals.stable.v1` instead.
"""
"narwhals.dtypes".msg = """
Import `dtypes` from `narwhals.stable.v1` instead.
"typing.Optional".msg = """
Use `Union[T, None]` instead.
`typing.Optional` is likely to be confused with `altair.typing.Optional`, \
which have a similar but different semantic meaning.
See https://github.com/vega/altair/pull/3449
"""

[tool.ruff.lint.per-file-ignores]
# Only enforce type annotation rules on public api
"!altair/vegalite/v5/api.py" = ["ANN"]
# Allow complex if/elif branching during tests
"tests/**/*.py"= ["C901"]

"!altair/vegalite/v5/api.py" = ["ANN"] # Only enforce annotation rules on public api
"tests/**/*.py" = ["C901"] # Allow complex if/elif branching during tests

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "lf"
# https://docs.astral.sh/ruff/formatter/#docstring-formatting
docstring-code-format = true
docstring-code-format = true # https://docs.astral.sh/ruff/formatter/#docstring-formatting
docstring-code-line-length = 88
line-ending = "lf"

[tool.pytest.ini_options]
# Pytest does not need to search these folders for test functions.
Expand Down
2 changes: 1 addition & 1 deletion sphinxext/code_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def validate_packages(packages: Any) -> str:
if len(split) == 1:
return f'["{split[0]}"]'
else:
return f'[{",".join(split)}]'
return f"[{','.join(split)}]"


def raw_html(text: str, /) -> nodes.raw:
Expand Down
Loading
Loading