Skip to content

Commit c763880

Browse files
committed
Replace cast with typing
1 parent 102e72b commit c763880

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

dash/_pages.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from pathlib import Path
99
from os.path import isfile, join
1010
from urllib.parse import parse_qs, unquote
11-
from typing import cast
1211

1312
import flask
1413

@@ -87,8 +86,12 @@ def _infer_path(module_name, template):
8786

8887

8988
def _module_name_is_package(module_name):
90-
file_path = cast(str, sys.modules[module_name].__file__) # to satisfy type checking
91-
return module_name in sys.modules and Path(file_path).name == "__init__.py"
89+
file_path = sys.modules[module_name].__file__
90+
return (
91+
file_path
92+
and module_name in sys.modules
93+
and Path(file_path).name == "__init__.py"
94+
)
9295

9396

9497
def _path_to_module_name(path):

dash/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from html import escape
1717
from functools import wraps
18-
from typing import Union, cast
18+
from typing import Union
1919
from .types import RendererHooks
2020

2121
logger = logging.getLogger()
@@ -121,7 +121,7 @@ def __setitem__(self, key, val):
121121
def update(self, other=None, **kwargs):
122122
# Overrides dict.update() to use __setitem__ above
123123
# Needs default `None` and `kwargs` to satisfy type checking
124-
source = cast(dict, other) if other is not None else kwargs
124+
source = other if other is not None else kwargs
125125
for k, v in source.items():
126126
self[k] = v
127127

dash/dash.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import base64
1919
import traceback
2020
from urllib.parse import urlparse
21-
from typing import Any, Callable, Dict, Optional, Union, Sequence, cast, Literal
21+
from typing import Any, Callable, Dict, Optional, Union, Sequence, Literal
2222

2323
import flask
2424

@@ -448,7 +448,6 @@ def __init__( # pylint: disable=too-many-statements
448448
if name is None:
449449
caller_name = getattr(server, "name", caller_name)
450450
elif isinstance(server, bool):
451-
name = name if name else caller_name
452451
self.server = flask.Flask(caller_name) if server else None # type: ignore
453452
else:
454453
raise ValueError("server must be a Flask app or a boolean")
@@ -457,7 +456,6 @@ def __init__( # pylint: disable=too-many-statements
457456
url_base_pathname, routes_pathname_prefix, requests_pathname_prefix
458457
)
459458

460-
name = cast(str, name) # to satisfy type checking
461459
self.config = AttributeDict(
462460
name=caller_name,
463461
assets_folder=os.path.join(
@@ -1788,7 +1786,7 @@ def enable_dev_tools(
17881786
dev_tools_silence_routes_logging: Optional[bool] = None,
17891787
dev_tools_disable_version_check: Optional[bool] = None,
17901788
dev_tools_prune_errors: Optional[bool] = None,
1791-
) -> None:
1789+
) -> bool:
17921790
"""Activate the dev tools, called by `run`. If your application
17931791
is served by wsgi and you want to activate the dev tools, you can call
17941792
this method out of `__main__`.

dash/testing/application_runners.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import logging
1010
import inspect
1111
import ctypes
12-
from typing import cast
1312

1413
import runpy
1514
import requests
@@ -354,11 +353,9 @@ def start(self, app, start_timeout=2, cwd=None): # type: ignore[reportIncompati
354353
# app is a string chunk, we make a temporary folder to store app.R
355354
# and its relevant assets
356355
tmp_dir = "/tmp" if not self.is_windows else os.getenv("TEMP")
357-
tmp_dir = cast(str, tmp_dir) # to satisfy type checking
356+
tmp_dir = str(tmp_dir) # to satisfy type checking
358357
hex_id = uuid.uuid4().hex
359-
self._tmp_app_path = cast(
360-
str, os.path.join(tmp_dir, hex_id)
361-
) # to satisfy type checking
358+
self._tmp_app_path = os.path.join(tmp_dir, hex_id)
362359
try:
363360
os.mkdir(self.tmp_app_path) # type: ignore[reportArgumentType]
364361
except OSError:

0 commit comments

Comments
 (0)