Skip to content

Commit c8073a8

Browse files
committed
feat: adding more type annotations to satisfy pyright
1 parent 0bd4452 commit c8073a8

File tree

25 files changed

+157
-133
lines changed

25 files changed

+157
-133
lines changed

components/dash-core-components/dash_core_components_base/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
send_string,
1414
)
1515

16-
__all__ = _components + [
16+
__all__ = _components + [ # type: ignore[reportUnsupportedDunderAll]
1717
"send_bytes",
1818
"send_data_frame",
1919
"send_file",

components/dash-table/dash_table_base/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# type: ignore
2+
13
import os as _os
24
import sys as _sys
35
import json

components/dash-table/src/dash-table/dash/DataTable.js

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -472,25 +472,14 @@ export const propTypes = {
472472
* View the documentation examples to learn more.
473473
*
474474
*/
475-
fixed_columns: PropTypes.oneOfType([
476-
PropTypes.exact({
477-
/**
478-
* Example `{'headers':False, 'data':0}` No columns are fixed (the default)
479-
*/
480-
481-
data: PropTypes.oneOf([0]),
482-
headers: PropTypes.oneOf([false])
483-
}),
484-
485-
PropTypes.exact({
486-
/**
487-
* Example `{'headers':True, 'data':1}` one column is fixed.
488-
*/
475+
fixed_columns: PropTypes.exact({
476+
/**
477+
* Example `{'headers':False, 'data':0}` No columns are fixed (the default)
478+
*/
489479

490-
data: PropTypes.number,
491-
headers: PropTypes.oneOf([true]).isRequired
492-
})
493-
]),
480+
data: PropTypes.number,
481+
headers: PropTypes.bool
482+
}),
494483

495484
/**
496485
* `fixed_rows` will "fix" the set of rows so that
@@ -505,24 +494,14 @@ export const propTypes = {
505494
* way that your columns are rendered or sized.
506495
* View the documentation examples to learn more.
507496
*/
508-
fixed_rows: PropTypes.oneOfType([
509-
PropTypes.exact({
510-
/**
511-
* Example `{'headers':False, 'data':0}` No rows are fixed (the default)
512-
*/
513-
514-
data: PropTypes.oneOf([0]),
515-
headers: PropTypes.oneOf([false])
516-
}),
517-
PropTypes.exact({
518-
/**
519-
* Example `{'headers':True, 'data':1}` one row is fixed.
520-
*/
497+
fixed_rows: PropTypes.exact({
498+
/**
499+
* Example `{'headers':False, 'data':0}` No rows are fixed (the default)
500+
*/
521501

522-
data: PropTypes.number,
523-
headers: PropTypes.oneOf([true]).isRequired
524-
})
525-
]),
502+
data: PropTypes.number,
503+
headers: PropTypes.bool
504+
}),
526505

527506
/**
528507
* If `single`, then the user can select a single column or group

dash/_callback.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,9 @@ def register_callback(
360360
# pylint: disable=too-many-locals
361361
def wrap_func(func):
362362

363-
if background is not None:
363+
if background is None:
364+
background_key = None
365+
else:
364366
background_key = BaseBackgroundCallbackManager.register_func(
365367
func,
366368
background.get("progress") is not None,
@@ -515,7 +517,7 @@ def add_context(*args, **kwargs):
515517
return to_json(response)
516518
else:
517519
try:
518-
output_value = _invoke_callback(func, *func_args, **func_kwargs)
520+
output_value = _invoke_callback(func, *func_args, **func_kwargs) # type: ignore[reportArgumentType]
519521
except PreventUpdate as err:
520522
raise err
521523
except Exception as err: # pylint: disable=broad-exception-caught
@@ -555,7 +557,7 @@ def add_context(*args, **kwargs):
555557
if NoUpdate.is_no_update(val):
556558
continue
557559
for vali, speci in (
558-
zip(val, spec) if isinstance(spec, list) else [[val, spec]]
560+
zip(val, spec) if isinstance(spec, list) else [[val, spec]] # type: ignore[reportArgumentType]]
559561
):
560562
if not NoUpdate.is_no_update(vali):
561563
has_update = True
@@ -590,6 +592,7 @@ def add_context(*args, **kwargs):
590592
dist = app.get_dist(diff_packages)
591593
response["dist"] = dist
592594

595+
jsonResponse = None
593596
try:
594597
jsonResponse = to_json(response)
595598
except TypeError:

dash/_callback_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,15 @@ def response(self):
207207

208208
@staticmethod
209209
@has_context
210-
def record_timing(name, duration=None, description=None):
210+
def record_timing(name, duration, description=None):
211211
"""Records timing information for a server resource.
212212
213213
:param name: The name of the resource.
214214
:type name: string
215215
216216
:param duration: The time in seconds to report. Internally, this
217217
is rounded to the nearest millisecond.
218-
:type duration: float or None
218+
:type duration: float
219219
220220
:param description: A description of the resource.
221221
:type description: string or None

dash/_grouping.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
structure
1414
1515
"""
16-
from dash.exceptions import InvalidCallbackReturnValue
16+
from .exceptions import InvalidCallbackReturnValue
1717
from ._utils import AttributeDict, stringify_id
1818

1919

dash/_jupyter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
import asyncio
23
import io
34
import inspect

dash/_pages.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import collections
22
import importlib
3+
import importlib.util # to make the type checker happy
34
import os
45
import re
56
import sys
@@ -85,10 +86,9 @@ def _infer_path(module_name, template):
8586

8687

8788
def _module_name_is_package(module_name):
88-
return (
89-
module_name in sys.modules
90-
and Path(sys.modules[module_name].__file__).name == "__init__.py"
91-
)
89+
file_path = sys.modules[module_name].__file__
90+
assert file_path is not None # to make type checker happy
91+
return module_name in sys.modules and Path(file_path).name == "__init__.py"
9292

9393

9494
def _path_to_module_name(path):
@@ -441,6 +441,9 @@ def _import_layouts_from_pages(pages_folder):
441441

442442
module_name = _infer_module_name(page_path)
443443
spec = importlib.util.spec_from_file_location(module_name, page_path)
444+
assert (
445+
spec is not None and spec.loader is not None
446+
) # to satisfy type checking
444447
page_module = importlib.util.module_from_spec(spec)
445448
spec.loader.exec_module(page_module)
446449
sys.modules[module_name] = page_module

dash/_utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
import uuid
55
import hashlib
6-
import collections
6+
from collections import abc
77
import subprocess
88
import logging
99
import io
@@ -15,8 +15,8 @@
1515

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

2121
logger = logging.getLogger()
2222

@@ -58,7 +58,7 @@ def generate_hash():
5858

5959
# pylint: disable=no-member
6060
def patch_collections_abc(member):
61-
return getattr(collections.abc, member)
61+
return getattr(abc, member)
6262

6363

6464
class AttributeDict(dict):
@@ -118,9 +118,11 @@ def __setitem__(self, key, val):
118118

119119
return super().__setitem__(key, val)
120120

121-
def update(self, other):
121+
def update(self, other=None, **kwargs):
122122
# Overrides dict.update() to use __setitem__ above
123-
for k, v in other.items():
123+
# Needs default `None` and `kwargs` to satisfy type checking
124+
source = cast(dict, other) if other is not None else kwargs
125+
for k, v in source.items():
124126
self[k] = v
125127

126128
# pylint: disable=inconsistent-return-statements
@@ -251,7 +253,7 @@ def gen_salt(chars):
251253
)
252254

253255

254-
class OrderedSet(collections.abc.MutableSet):
256+
class OrderedSet(abc.MutableSet):
255257
def __init__(self, *args):
256258
self._data = []
257259
for i in args:

dash/_watch.py

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

77
def watch(folders, on_change, pattern=None, sleep_time=0.1):
88
pattern = re.compile(pattern) if pattern else None
9-
watched = collections.defaultdict(lambda: -1)
9+
watched = collections.defaultdict(lambda: -1.0)
1010

1111
def walk():
1212
walked = []

0 commit comments

Comments
 (0)