Skip to content

Commit ef3c5f5

Browse files
authored
chore(pyright): Prep pyright version for release; pyright >= v1.1.407 (#2120)
1 parent ef0c82d commit ef3c5f5

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ dev = [
101101
"isort>=5.10.1",
102102
"libsass>=0.23.0",
103103
"brand_yml>=0.1.0",
104-
"pyright==1.1.398",
104+
"pyright>=1.1.407",
105105
"pre-commit>=2.15.0",
106106
"wheel",
107107
"matplotlib",

shiny/_main_create.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,15 @@ class ShinyTemplate:
8787
type: str = "app"
8888
title: str | None = None
8989
description: str | None = None
90-
next_steps: list[str] = field(default_factory=list)
91-
follow_up: list[ShinyTemplateFollowUp] = field(default_factory=list)
90+
next_steps: list[str] = field( # pyright: ignore[reportUnknownVariableType]
91+
default_factory=list
92+
)
93+
# Black can't handle this line properly
94+
# It should have `# pyright: ignore[reportUnknownVariableType]` but
95+
# pyright gets confused with the comment in the middle of an expression
96+
follow_up: list[ShinyTemplateFollowUp] = field( # pyright: ignore
97+
default_factory=list
98+
)
9299
_express_available: bool | None = None
93100

94101
@property

shiny/express/expressify_decorator/_expressify.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class WrappedFunction(Protocol):
5151

5252
def unwrap(fn: TFunc) -> TFunc:
5353
while isinstance(fn, WrappedFunction):
54-
fn = fn.__wrapped__
54+
fn = fn.__wrapped__ # pyright: ignore[reportAssignmentType]
5555
return fn
5656

5757

shiny/reactive/_poll.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,31 @@ def file_reader(
273273
if isinstance(filepath, str):
274274
# Normalize filepath so it's always a function
275275

276-
filepath_value = filepath
276+
filepath_str_value: str = filepath
277277

278278
def filepath_func_str() -> str:
279-
return filepath_value
279+
return filepath_str_value
280280

281-
filepath = filepath_func_str
281+
filepath_fn = filepath_func_str
282282
elif isinstance(filepath, os.PathLike):
283-
filepath_value = filepath
283+
# Can't use `# pyright: ignore[reportUnknownVariableType]` on the line below as
284+
# Black can't format it properly
285+
filepath_path_value: os.PathLike[str] = filepath # pyright: ignore
284286

285287
def filepath_func_pathlike() -> os.PathLike[str]:
286-
return filepath_value
288+
return filepath_path_value
287289

288-
filepath = filepath_func_pathlike
290+
filepath_fn = filepath_func_pathlike
291+
elif callable(filepath):
292+
filepath_fn = filepath
293+
else:
294+
raise TypeError(
295+
"`filepath` argument to reactive.file_reader() must be a str, "
296+
"os.PathLike, or a no-argument function that returns one of those types."
297+
)
289298

290299
def check_timestamp():
291-
path = filepath()
300+
path = filepath_fn()
292301
return (path, os.path.getmtime(path), os.path.getsize(path))
293302

294303
def wrapper(fn: Callable[[], T]) -> Callable[[], T]:

shiny/render/_data_frame_utils/_reactive_method.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ def calc_fn():
106106
# be garbage collected until `self` is garbage collected.
107107
if not hasattr(self.__dict__, "_reactive_calc_method"):
108108
self.__dict__["_reactive_calc_method"] = {}
109-
self_reactive_calc_cache: dict[str, reactive.Calc_[R]] = self.__dict__[
110-
"_reactive_calc_method"
111-
]
109+
110+
# Can't use `# pyright: ignore[reportUnknownVariableType]` on the line below
111+
# as Black can't format it properly
112+
self_reactive_calc_cache: dict[str, reactive.Calc_[R]] = ( # type: ignore
113+
self.__dict__["_reactive_calc_method"]
114+
)
112115
if hasattr(self_reactive_calc_cache, fn.__name__):
113116
raise AttributeError(
114117
f"Reactive calc method `{fn.__name__}` has already be cached on self: {self}"

shiny/ui/_theme_brand.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
if TYPE_CHECKING:
88
from brand_yml import Brand
9+
910
from htmltools import HTMLDependency
1011

1112
from .._versions import bootstrap as v_bootstrap
@@ -80,7 +81,7 @@ def _validate_defaults(self, x: Any) -> dict[str, YamlScalarType] | None:
8081
f"Invalid brand `{self._path}.defaults`, must be a dictionary."
8182
)
8283

83-
y: dict[Any, Any] = x
84+
y: dict[Any, Any] = x # pyright: ignore[reportUnknownVariableType]
8485

8586
if not all([isinstance(k, str) for k in y.keys()]):
8687
raise ValueError(

tests/playwright/shiny/inputs/input_file/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def summary():
5555

5656
# input.stats() is a list of strings; subset the columns based on the selected
5757
# checkboxes
58-
return info_df.loc[:, input.stats()]
58+
stats_cols: list[str] = input.stats()
59+
return info_df.loc[:, stats_cols]
5960

6061
@render.text
6162
def file2_info():

0 commit comments

Comments
 (0)