Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#3416)
Browse files Browse the repository at this point in the history
<!--pre-commit.ci start-->
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.6 →
v0.9.1](astral-sh/ruff-pre-commit@v0.8.6...v0.9.1)
<!--pre-commit.ci end-->

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Jan 14, 2025
1 parent ac11d0c commit becf8e5
Show file tree
Hide file tree
Showing 35 changed files with 181 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repos:
- id: typos

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
rev: v0.9.1
hooks:
# Run the linter
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion marimo/_ai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __call__(
client: AzureOpenAI | OpenAI = AzureOpenAI(
api_key=self._require_api_key,
api_version=api_version,
azure_endpoint=f"{cast(str,parsed_url.scheme)}://{cast(str,parsed_url.hostname)}",
azure_endpoint=f"{cast(str, parsed_url.scheme)}://{cast(str, parsed_url.hostname)}",
)
else:
client = OpenAI(
Expand Down
4 changes: 1 addition & 3 deletions marimo/_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,7 @@ def new(
default=120,
show_default=True,
type=int,
help=(
"Seconds to wait before closing a session on " "websocket disconnect."
),
help=("Seconds to wait before closing a session on websocket disconnect."),
)
@click.option(
"--watch",
Expand Down
4 changes: 3 additions & 1 deletion marimo/_plugins/stateless/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def tree(
Example:
```python3
mo.tree(["entry", "another entry", {"key": [0, 1, 2]}], label="A tree.")
mo.tree(
["entry", "another entry", {"key": [0, 1, 2]}], label="A tree."
)
```
Args:
Expand Down
3 changes: 1 addition & 2 deletions marimo/_plugins/ui/_impl/altair_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ def __init__(

if not isinstance(chart, (alt.TopLevelMixin)):
raise ValueError(
"Invalid type for chart: "
f"{type(chart)}; expected altair.Chart"
f"Invalid type for chart: {type(chart)}; expected altair.Chart"
)

# Make full-width if no width is specified
Expand Down
6 changes: 3 additions & 3 deletions marimo/_plugins/ui/_impl/dataframes/transforms/print_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def python_print_transforms(
strs: List[str] = []
for transform in transforms:
strs.append(
f"{df_next_name} = {print_transform(df_next_name,all_columns, transform)}" # noqa: E501
f"{df_next_name} = {print_transform(df_next_name, all_columns, transform)}" # noqa: E501
)
return "\n".join([f"{df_next_name} = {df_name}"] + strs)

Expand Down Expand Up @@ -128,7 +128,7 @@ def generate_where_clause(df_name: str, where: Condition) -> str:
)
if not column_ids:
return f"{df_name}.agg({_list_of_strings(aggregations)})"
return f'{df_name}.agg({{{", ".join(f"{_as_literal(column_id)}: {_list_of_strings(aggregations)}" for column_id in column_ids)}}})' # noqa: E501
return f"{df_name}.agg({{{', '.join(f'{_as_literal(column_id)}: {_list_of_strings(aggregations)}' for column_id in column_ids)}}})" # noqa: E501

elif transform.type == TransformType.GROUP_BY:
column_ids, aggregation, drop_na = (
Expand Down Expand Up @@ -480,7 +480,7 @@ def _as_literal(value: Any) -> str:

def _list_of_strings(value: Union[List[Any], Any]) -> str:
if isinstance(value, list):
return f'[{", ".join(_as_literal(v) for v in value)}]'
return f"[{', '.join(_as_literal(v) for v in value)}]"
return _as_literal(value)


Expand Down
6 changes: 3 additions & 3 deletions marimo/_plugins/ui/_impl/dataframes/transforms/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ def __hash__(self) -> int:

def __post_init__(self) -> None:
if self.operator == "in":
assert isinstance(
self.value, list
), "value must be a list for 'in' operator"
assert isinstance(self.value, list), (
"value must be a list for 'in' operator"
)


@dataclass
Expand Down
4 changes: 3 additions & 1 deletion marimo/_runtime/app_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def mode(self) -> Optional[RunMode]:
```python
# Only show this content when editing the notebook
mo.md("# Developer Notes") if mo.app_meta().mode == "edit" else None
mo.md(
"# Developer Notes"
) if mo.app_meta().mode == "edit" else None
```
Returns:
Expand Down
12 changes: 6 additions & 6 deletions marimo/_runtime/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def execution_requests(self) -> List[ExecutionRequest]:
]

def __post_init__(self) -> None:
assert len(self.cell_ids) == len(
self.codes
), "Mismatched cell_ids and codes"
assert len(self.cell_ids) == len(self.codes), (
"Mismatched cell_ids and codes"
)


@dataclass
Expand All @@ -74,9 +74,9 @@ class SetUIElementValueRequest:
token: str = field(default_factory=lambda: str(uuid4()))

def __post_init__(self) -> None:
assert len(self.object_ids) == len(
self.values
), "Mismatched object_ids and values"
assert len(self.object_ids) == len(self.values), (
"Mismatched object_ids and values"
)

@staticmethod
def from_ids_and_values(
Expand Down
3 changes: 1 addition & 2 deletions marimo/_runtime/runner/hooks_on_finish.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def _send_cancellation_errors(runner: cell_runner.Runner) -> None:
exception_type = type(runner.exceptions[raising_cell]).__name__
data = MarimoExceptionRaisedError(
msg=(
"An ancestor raised an exception "
f"({exception_type}): "
f"An ancestor raised an exception ({exception_type}): "
),
exception_type=exception_type,
raising_cell=raising_cell,
Expand Down
4 changes: 3 additions & 1 deletion marimo/_runtime/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ def app_meta() -> AppMeta:
import altair as alt
# Enable dark theme for Altair when marimo is in dark mode
alt.themes.enable("dark" if mo.app_meta().theme == "dark" else "default")
alt.themes.enable(
"dark" if mo.app_meta().theme == "dark" else "default"
)
```
Show content only in edit mode:
Expand Down
6 changes: 3 additions & 3 deletions marimo/_save/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ def strip_function(fn: Callable[..., Any]) -> ast.Module:
code, _ = inspect.getsourcelines(fn)
function_ast = ast.parse(textwrap.dedent("".join(code)))
body = function_ast.body.pop()
assert isinstance(
body, (ast.FunctionDef, ast.AsyncFunctionDef)
), "Expected a function definition"
assert isinstance(body, (ast.FunctionDef, ast.AsyncFunctionDef)), (
"Expected a function definition"
)
extracted = ast.Module(body.body, type_ignores=[])
module = RemoveReturns().visit(extracted)
assert isinstance(module, ast.Module), "Expected a module"
Expand Down
6 changes: 3 additions & 3 deletions marimo/_save/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ def __init__(
if not scoped_refs:
scoped_refs = set()
else:
assert (
not apply_content_hash
), "scoped_refs should only be used with deferred hashing."
assert not apply_content_hash, (
"scoped_refs should only be used with deferred hashing."
)

self._hash: Optional[str] = None
self.graph = graph
Expand Down
6 changes: 3 additions & 3 deletions marimo/_save/loaders/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def cache_attempt(
loaded = self.load_cache(hashed_context, cache_type)
# TODO: Consider more robust verification
assert loaded.hash == hashed_context, INCONSISTENT_CACHE_BOILER_PLATE
assert set(defs | stateful_refs) == set(
loaded.defs
), INCONSISTENT_CACHE_BOILER_PLATE
assert set(defs | stateful_refs) == set(loaded.defs), (
INCONSISTENT_CACHE_BOILER_PLATE
)
return Cache(
loaded.defs,
hashed_context,
Expand Down
6 changes: 3 additions & 3 deletions marimo/_save/loaders/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def cache_hit(self, hashed_context: str, cache_type: CacheType) -> bool:
return self._maybe_lock(lambda: key in self._cache)

def load_cache(self, hashed_context: str, cache_type: CacheType) -> Cache:
assert self.cache_hit(
hashed_context, cache_type
), INCONSISTENT_CACHE_BOILER_PLATE
assert self.cache_hit(hashed_context, cache_type), (
INCONSISTENT_CACHE_BOILER_PLATE
)
self.hits += 1
key = self.build_path(hashed_context, cache_type)
if self.is_lru:
Expand Down
8 changes: 4 additions & 4 deletions marimo/_save/loaders/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def cache_hit(self, hashed_context: str, cache_type: CacheType) -> bool:
return os.path.exists(path) and os.path.getsize(path) > 0

def load_cache(self, hashed_context: str, cache_type: CacheType) -> Cache:
assert self.cache_hit(
hashed_context, cache_type
), INCONSISTENT_CACHE_BOILER_PLATE
assert self.cache_hit(hashed_context, cache_type), (
INCONSISTENT_CACHE_BOILER_PLATE
)
with open(self.build_path(hashed_context, cache_type), "rb") as handle:
cache = pickle.load(handle)
assert isinstance(cache, Cache), (
"Excepted cache object, got" f"{type(cache)} ",
f"Excepted cache object, got{type(cache)} ",
INCONSISTENT_CACHE_BOILER_PLATE,
)
return cache
Expand Down
5 changes: 2 additions & 3 deletions marimo/_save/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def __exit__(
sys.settrace(self._old_trace) # Clear to previous set trace.
if not self._entered_trace:
raise CacheException(
("Unexpected block format" f"{UNEXPECTED_FAILURE_BOILERPLATE}")
(f"Unexpected block format{UNEXPECTED_FAILURE_BOILERPLATE}")
)

# Backfill the loaded values into global scope.
Expand All @@ -493,8 +493,7 @@ def __exit__(
# NB: exception is a type.
if exception:
assert not isinstance(instance, SkipWithBlock), (
"Cache was not correctly set"
f"{UNEXPECTED_FAILURE_BOILERPLATE}"
f"Cache was not correctly set{UNEXPECTED_FAILURE_BOILERPLATE}"
)
if isinstance(instance, BaseException):
raise instance from CacheException("Failure during save.")
Expand Down
4 changes: 2 additions & 2 deletions marimo/_server/ai/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_system_prompt(
"Do not output markdown or backticks.",
] + language_rules[language]
rules = "\n".join(
f"{i+1}. {rule}" for i, rule in enumerate(all_rules)
f"{i + 1}. {rule}" for i, rule in enumerate(all_rules)
)
system_prompt = (
f"You are a helpful assistant that can answer questions about {language}."
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_chat_system_prompt(
continue

rules = "\n".join(
f"{i+1}. {rule}"
f"{i + 1}. {rule}"
for i, rule in enumerate(language_rules[language])
)

Expand Down
2 changes: 1 addition & 1 deletion marimo/_server/api/endpoints/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_openai_client(config: MarimoConfig) -> "OpenAI":
api_key=key,
api_version=api_version,
azure_deployment=deployment_model,
azure_endpoint=f"{cast(str,parsed_url.scheme)}://{cast(str,parsed_url.hostname)}",
azure_endpoint=f"{cast(str, parsed_url.scheme)}://{cast(str, parsed_url.hostname)}",
)
else:
return OpenAI(
Expand Down
2 changes: 1 addition & 1 deletion marimo/_server/api/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ async def _proxy_websocket(
websocket = WebSocket(scope, receive=receive, send=send)
original_params = websocket.query_params
if original_params:
ws_url = f"{ws_url}?{'&'.join(f'{k}={v}' for k,v in original_params.items())}"
ws_url = f"{ws_url}?{'&'.join(f'{k}={v}' for k, v in original_params.items())}"
await websocket.accept()

async with connect(ws_url) as ws_client:
Expand Down
36 changes: 18 additions & 18 deletions marimo/_server/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def zip(

# Validate same length
def __post_init__(self) -> None:
assert len(self.object_ids) == len(
self.values
), "Mismatched object_ids and values"
assert len(self.object_ids) == len(self.values), (
"Mismatched object_ids and values"
)


@dataclass
Expand Down Expand Up @@ -89,9 +89,9 @@ def as_execution_request(self) -> ExecuteMultipleRequest:

# Validate same length
def __post_init__(self) -> None:
assert len(self.cell_ids) == len(
self.codes
), "Mismatched cell_ids and codes"
assert len(self.cell_ids) == len(self.codes), (
"Mismatched cell_ids and codes"
)


@dataclass
Expand Down Expand Up @@ -121,15 +121,15 @@ class SaveNotebookRequest:

# Validate same length
def __post_init__(self) -> None:
assert len(self.cell_ids) == len(
self.codes
), "Mismatched cell_ids and codes"
assert len(self.cell_ids) == len(
self.names
), "Mismatched cell_ids and names"
assert len(self.cell_ids) == len(
self.configs
), "Mismatched cell_ids and configs"
assert len(self.cell_ids) == len(self.codes), (
"Mismatched cell_ids and codes"
)
assert len(self.cell_ids) == len(self.names), (
"Mismatched cell_ids and names"
)
assert len(self.cell_ids) == len(self.configs), (
"Mismatched cell_ids and configs"
)


@dataclass
Expand All @@ -147,9 +147,9 @@ def __post_init__(self) -> None:
f'File "{self.source}" does not exist.'
+ "Please save the notebook and try again."
)
assert not os.path.exists(
self.destination
), f'File "{destination}" already exists in this directory.'
assert not os.path.exists(self.destination), (
f'File "{destination}" already exists in this directory.'
)


@dataclass
Expand Down
12 changes: 6 additions & 6 deletions marimo/_server/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def __init__(self, prefix: str = "") -> None:

def __post_init__(self) -> None:
if self.prefix:
assert self.prefix.startswith(
"/"
), "Path prefix must start with '/'"
assert not self.prefix.endswith(
"/"
), "Path prefix must not end with '/'"
assert self.prefix.startswith("/"), (
"Path prefix must start with '/'"
)
assert not self.prefix.endswith("/"), (
"Path prefix must not end with '/'"
)

def post(
self, path: str
Expand Down
6 changes: 3 additions & 3 deletions marimo/_server/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ def add_consumer(
self.consumers[consumer] = consumer_id
self.disposables[consumer] = dispose
if main:
assert (
self.main_consumer is None
), "Main session consumer already exists"
assert self.main_consumer is None, (
"Main session consumer already exists"
)
self.main_consumer = consumer

def remove_consumer(self, consumer: SessionConsumer) -> None:
Expand Down
Loading

0 comments on commit becf8e5

Please sign in to comment.