Skip to content

Commit 249cc00

Browse files
raethleinkajarenc
authored andcommitted
Update mypy and ruff target-version to Python 3.9 and use ruff 0.9.4 (#10318)
In #9919 we set the min Python version to 3.9, so it's time to update the ruff format target version also to Python 3.9. Also, we bump the ruff version from `0.8.6` to `0.9.4`. We also bump the min Python version used by `mypy` from `3.8` to `3.9`. Fixes: - [UP035] Import from `collections.abc` instead: `Sequence`, `typing.Tuple` is deprecated, use `tuple` instead - [UP006] Use `tuple` instead of `Tuple` for type annotation - [TC003] Move standard library import `collections.abc.*` into a type-checking block - No test updates because this is formatting only. Existing tests should catch any issues. --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
1 parent 0a9d6fa commit 249cc00

File tree

111 files changed

+742
-541
lines changed

Some content is hidden

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

111 files changed

+742
-541
lines changed

.github/scripts/build_info.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def check_if_pr_has_label(label: str, action: str) -> bool:
173173
pr_labels = get_current_pr_labels()
174174
if label in pr_labels:
175175
print(f"PR has the following labels: {pr_labels}")
176-
print(f"{action}, because PR has {label !r} label.")
176+
print(f"{action}, because PR has {label!r} label.")
177177
return True
178178
return False
179179

@@ -293,11 +293,12 @@ def save_output_variables(variables: dict[str, str]) -> None:
293293
Saves build variables
294294
"""
295295
print("Saving output variables")
296-
with open(
297-
os.environ.get(GITHUB_ENV_ENV_VAR, "/dev/null"), "w+"
298-
) as github_env_file, open(
299-
os.environ.get(GITHUB_OUTPUT_ENV_VAR, "/dev/null"), "w+"
300-
) as github_output_file:
296+
with (
297+
open(os.environ.get(GITHUB_ENV_ENV_VAR, "/dev/null"), "w+") as github_env_file,
298+
open(
299+
os.environ.get(GITHUB_OUTPUT_ENV_VAR, "/dev/null"), "w+"
300+
) as github_output_file,
301+
):
301302
for target_file in [sys.stdout, github_env_file, github_output_file]:
302303
for name, value in variables.items():
303304
target_file.write(f"{name}={value}\n")

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
# because the files were linted after trying to do the first commit.
2121
repos:
2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
# Ruff version.
24-
rev: v0.8.0
23+
# We fix ruff to a version to be in sync with the dev-requirements:
24+
rev: v0.9.4
2525
hooks:
2626
# Run the linter.
2727
- id: ruff

.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include = [
2020
"e2e_playwright/**/*.py",
2121
"scripts/**/*.py",
2222
]
23-
target-version = 'py38'
23+
target-version = 'py39'
2424
line-length = 88
2525

2626
[format]

e2e_playwright/auth_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import time
1818
from tempfile import NamedTemporaryFile
19-
from typing import Generator
19+
from typing import TYPE_CHECKING
2020

2121
import pytest
2222
from playwright.sync_api import Page, expect
@@ -28,6 +28,9 @@
2828
)
2929
from e2e_playwright.shared.app_utils import get_button, get_markdown
3030

31+
if TYPE_CHECKING:
32+
from collections.abc import Generator
33+
3134
AUTH_SECRETS_TEMPLATE = """
3235
[auth]
3336
redirect_uri = "http://localhost:{app_port}/oauth2callback"

e2e_playwright/conftest.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from pathlib import Path
3434
from random import randint
3535
from tempfile import TemporaryFile
36-
from typing import TYPE_CHECKING, Any, Callable, Generator, Literal, Protocol
36+
from typing import TYPE_CHECKING, Any, Callable, Literal, Protocol
3737
from urllib import parse
3838

3939
import pytest
@@ -57,6 +57,7 @@
5757
)
5858

5959
if TYPE_CHECKING:
60+
from collections.abc import Generator
6061
from types import ModuleType
6162

6263

@@ -397,9 +398,11 @@ def _open_app(iframe_element_attrs: IframedPageAttrs | None = None) -> FrameLoca
397398
<body style="height: 100%;">
398399
<iframe
399400
src={src}
400-
id={_iframe_element_attrs.element_id
401-
if _iframe_element_attrs.element_id
402-
else ""}
401+
id={
402+
_iframe_element_attrs.element_id
403+
if _iframe_element_attrs.element_id
404+
else ""
405+
}
403406
title="Iframed Streamlit App"
404407
allow="clipboard-write; microphone;"
405408
sandbox="allow-popups allow-same-origin allow-scripts allow-downloads"
@@ -754,7 +757,7 @@ def compare(
754757

755758
test_failure_messages.append(
756759
f"Snapshot mismatch for {snapshot_file_name} ({mismatch} pixels difference;"
757-
f" {mismatch/total_pixels * 100:.2f}%)"
760+
f" {mismatch / total_pixels * 100:.2f}%)"
758761
)
759762

760763
yield compare

e2e_playwright/shared/app_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
import platform
1818
import re
19-
from typing import Literal, Pattern
19+
from re import Pattern
20+
from typing import Literal
2021

2122
from playwright.sync_api import Frame, Locator, Page, expect
2223

lib/dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pre-commit
22
# We fix ruff to a version to be in sync with the pre-commit hook:
3-
ruff==0.8.*
3+
ruff==0.9.4
44
# as soon as the error reported in https://github.com/python/mypy/issues/17604
55
# is released for mypy, we can update to version 1.11
66
mypy>=1.4, <1.11

lib/mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
python_version = 3.8
2+
python_version = 3.9
33
cache_dir = .mypy_cache
44

55
# TODO(nate): Additional strictness checks to work towards.

lib/streamlit/auth_util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
from __future__ import annotations
1616

17+
from collections.abc import Mapping
1718
from datetime import datetime, timedelta, timezone
18-
from typing import TYPE_CHECKING, Any, Mapping, TypedDict, cast
19+
from typing import TYPE_CHECKING, Any, TypedDict, cast
1920

2021
from streamlit import config
2122
from streamlit.errors import StreamlitAuthError

lib/streamlit/commands/echo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
import re
2020
import textwrap
2121
import traceback
22-
from typing import Any, Iterable
22+
from typing import TYPE_CHECKING, Any
2323

2424
from streamlit.runtime.metrics_util import gather_metrics
2525

26+
if TYPE_CHECKING:
27+
from collections.abc import Iterable
28+
2629
_SPACES_RE = re.compile("\\s*")
2730
_EMPTY_LINE_RE = re.compile("\\s*\n")
2831

0 commit comments

Comments
 (0)