Skip to content

Commit

Permalink
Fix type annotation throughout SIFT
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Aug 3, 2021
1 parent b227a54 commit 6aa622f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion uwsift/model/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def _product_info_under_playhead_for_family(self, family: str) -> typ.Mapping:
"""
raise NotImplementedError("need to consult mdb to get product info dictionary under playhead")

def get_info(self, dex: list[int, UUID]):
def get_info(self, dex: typ.Union[int, UUID]):
"""return info dictionary with top z-order at 0, going downward
"""
if isinstance(dex, UUID):
Expand Down
8 changes: 4 additions & 4 deletions uwsift/view/timeline/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ def __init__(self, time_base: datetime = None, time_unit: timedelta = None, trac
self._time_unit = time_unit
self._track_height = track_height or GFXC.track_height

def calc_time_duration(self, scene_x: [float, None], scene_w: [float, None]) -> Tuple[
Optional[datetime], Optional[timedelta]]:
def calc_time_duration(self, scene_x: Optional[float], scene_w: Optional[float]
) -> Tuple[Optional[datetime], Optional[timedelta]]:
"""Calculate time and duration given scene X coordinate and width (from QRectF typically)
Args:
Expand All @@ -151,8 +151,8 @@ def calc_track_pixel_y_center(self, z: int):
"""
return self._track_height * (0.5 + float(self._max_z - z))

def calc_scene_rect(self, ztd: ztdtup = None, z: int = None, t: datetime = None, d: timedelta = None) -> [QRectF,
None]:
def calc_scene_rect(self, ztd: ztdtup = None, z: int = None, t: datetime = None, d: timedelta = None
) -> Optional[QRectF]:
"""
calculate scene coordinates given time and Z
Args:
Expand Down
6 changes: 3 additions & 3 deletions uwsift/view/timeline/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
:license: GPLv3, see LICENSE for more details
"""
import logging
from typing import Mapping, Any, Tuple
from typing import Mapping, Any, Tuple, Union
from uuid import UUID
from weakref import ref
import pickle as pkl
Expand Down Expand Up @@ -131,7 +131,7 @@ class QTrackItem(QGraphicsObject):
_metadata: Mapping = None
_tooltip: str = None
_state: Flags = None # VisualState Flags determine how it's being presented
_colormap: [QGradient, QImage, QPixmap] = None
_colormap: Union[QGradient, QImage, QPixmap] = None
_min: float = None
_max: float = None
_dragging: bool = False # whether or not a drag is in progress across this item
Expand All @@ -146,7 +146,7 @@ class QTrackItem(QGraphicsObject):

def __init__(self, scene, scale: CoordTransform, track: str, z: int,
title: str, subtitle: str = None, icon: QIcon = None, metadata: dict = None,
tooltip: str = None, state: Flags = None, colormap: [QGradient, QImage] = None,
tooltip: str = None, state: Flags = None, colormap: Union[QGradient, QImage, QPixmap] = None,
min: float = None, max: float = None):
"""Create a track and connect it to its Scene
"""
Expand Down
10 changes: 6 additions & 4 deletions uwsift/view/timeline/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import sys
import unittest
from datetime import datetime, timedelta
from typing import Tuple, Optional, Mapping, List, Callable, Set, Iterable, Sequence, Any
from typing import Tuple, Optional, Mapping, List, Callable, Set, Iterable, Sequence, Any, Union
from uuid import UUID

from PyQt5.QtCore import QRectF, Qt, pyqtSignal
Expand Down Expand Up @@ -421,7 +421,7 @@ def iterate_track_info(self, start_z: int = 0, stop_z: Optional[int] = None):
"""Yield series of track information tuples which will be used to generate/update QTrackItems
"""

def get(self, item: [UUID, str]) -> [QTrackItem, QFrameItem, None]:
def get(self, item: Union[UUID, str]) -> Union[QTrackItem, QFrameItem, None]:
if isinstance(item, UUID):
z = self._frame_items.get(item)
elif isinstance(item, str):
Expand Down Expand Up @@ -469,7 +469,7 @@ def menu_for_track(self, track: str, frame: Optional[UUID] = None) -> Optional[
LOG.warning("using base class menu_for_track which does nothing")
return None

def update(self, changed_tracks: [Set[str], None] = None, changed_frame_uuids: [Set[UUID], None] = None):
def update(self, changed_tracks: Optional[Set[str]] = None, changed_frame_uuids: Optional[Set[UUID]] = None):
"""Populate or update scene, returning number of items changed in scene
Does not add new items for tracks and frames already present
Parameters serve only as hints
Expand All @@ -485,7 +485,9 @@ def __init__(self, *args, **kwargs):
super(TestScene, self).__init__(*args, **kwargs)
# assert(hasattr(self, '_track_order'))

def update(self, changed_tracks: [Set[str], None] = None, changed_frame_uuids: [Set[UUID], None] = None) -> int:
def update(self,
changed_tracks: Optional[Set[str]] = None,
changed_frame_uuids: Optional[Set[UUID]] = None) -> int:
if self._did_populate:
return 0
self._test_populate()
Expand Down
4 changes: 2 additions & 2 deletions uwsift/workspace/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import sys
import unittest
from datetime import datetime
from typing import List, Iterable, Mapping
from typing import List, Iterable, Mapping, Union

from PyQt5.QtCore import QObject

Expand Down Expand Up @@ -130,7 +130,7 @@ def _touch(self):
os.utime(self._timestamp_path)
return mtime

def __init__(self, ws: [Workspace, _workspace_test_proxy]):
def __init__(self, ws: Union[Workspace, _workspace_test_proxy]):
super(ResourceSearchPathCollector, self).__init__()
self._ws = ws
self._paths = []
Expand Down

0 comments on commit 6aa622f

Please sign in to comment.