Skip to content

Commit 20e0b2c

Browse files
committed
Cleanup and typing
1 parent 223f180 commit 20e0b2c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/omnipy/data/helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,11 @@ def get_special_methods_info_dict() -> dict[str, MethodInfo]:
148148
'_pydevd_bundle.pydevd_exec2',
149149
]
150150
validate_cls_counts: defaultdict[str, int] = defaultdict(int)
151-
ResetSolutionTuple = NamedTuple('ResetSolutionTuple', [('reset_solution', ContextManager[None]),
152-
('snapshot_taken', bool)])
151+
152+
153+
class ResetSolutionTuple(NamedTuple):
154+
reset_solution: ContextManager[None]
155+
snapshot_taken: bool
153156

154157

155158
def debug_get_sorted_validate_counts() -> dict[str, int]:

src/omnipy/data/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
from omnipy.api.protocols.private.util import IsSnapshotWrapper
3838
from omnipy.api.typedefs import TypeForm
3939
from omnipy.data.data_class_creator import DataClassBase, DataClassBaseMeta
40-
from omnipy.data.missing import parse_none_according_to_model
4140
from omnipy.data.helpers import (cleanup_name_qualname_and_module,
4241
get_special_methods_info_dict,
4342
get_terminal_size,
@@ -48,6 +47,7 @@
4847
validate_cls_counts,
4948
waiting_for_terminal_repr,
5049
YesNoMaybe)
50+
from omnipy.data.missing import parse_none_according_to_model
5151
from omnipy.util.contexts import (hold_and_reset_prev_attrib_value,
5252
LastErrorHolder,
5353
nothing,

src/omnipy/util/helpers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
Mapping,
3030
overload,
3131
Protocol,
32+
TypeGuard,
3233
TypeVar,
3334
Union)
3435
from weakref import WeakKeyDictionary, WeakValueDictionary
@@ -50,6 +51,8 @@
5051
_ValT = TypeVar('_ValT', bound=object)
5152
_ContentsT = TypeVar('_ContentsT', bound=object)
5253

54+
T = TypeVar('T')
55+
5356
Dictable = Mapping[_KeyT, Any] | Iterable[tuple[_KeyT, Any]]
5457

5558

@@ -204,9 +207,9 @@ def all_type_variants(
204207
return (cast(type | GenericAlias, in_type),)
205208

206209

207-
def is_iterable(obj: object) -> bool:
210+
def is_iterable(obj: Iterable[T] | T) -> TypeGuard[Iterable[T]]:
208211
try:
209-
iter(obj) # type: ignore[call-overload]
212+
iter(obj) # type: ignore[arg-type]
210213
return True
211214
except TypeError:
212215
return False

0 commit comments

Comments
 (0)