Skip to content

Commit

Permalink
Resolve mypy issues in 'qml_utils.py'
Browse files Browse the repository at this point in the history
Get rid of

uwsift/control/qml_utils.py:87: error: Name "layerModel" already defined on line 83  [no-redef]
uwsift/control/qml_utils.py:96: error: Name "convFuncModel" already defined on line 92  [no-redef]
uwsift/control/qml_utils.py:132: error: Name "layerToDisplay" already defined on line 127  [no-redef]
uwsift/control/qml_utils.py:144: error: Name "dateToDisplay" already defined on line 137  [no-redef]
uwsift/control/qml_utils.py:221: error: Property "timestamps" defined in "TimebaseModel" is read-only  [misc]
uwsift/control/qml_utils.py:222: error: Cannot assign to a method  [assignment]
uwsift/control/qml_utils.py:222: error: Incompatible types in assignment (expression has type "None", variable has type "Callable[..., Any]")  [assignment]
uwsift/control/qml_utils.py:243: error: Name "currentTimestamp" already defined on line 239  [no-redef]
uwsift/control/qml_utils.py:261: error: Name "timestamps" already defined on line 248  [no-redef]
uwsift/control/qml_utils.py:261: error: "Callable[[TimebaseModel], Any]" has no attribute "setter"  [attr-defined]

by
- ignoring false positives for pyqtProperty setters, see
  python/mypy#9911
- Avoiding to initialize variable with None which can also be
  initialized with something more useful right away.
  • Loading branch information
Alexandra Melzer authored and askalex committed Jan 3, 2023
1 parent d44d5e7 commit e825d3b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions uwsift/control/qml_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def set_convenience_functions(self, conv_funcs):
def layerModel(self):
return self._qml_layer_model

@layerModel.setter
@layerModel.setter # type: ignore # mypy bug #9911
def layerModel(self, new_model):
self._qml_layer_model = new_model
self.layerModelChanged.emit()
Expand All @@ -93,7 +93,7 @@ def layerModel(self, new_model):
def convFuncModel(self):
return self._conv_func_model

@convFuncModel.setter
@convFuncModel.setter # type: ignore # mypy bug #9911
def convFuncModel(self, new_model):
self._conv_func_model = new_model
self.convFuncModelChanged.emit()
Expand Down Expand Up @@ -129,7 +129,7 @@ def layerToDisplay(self):
return self._layer_to_display

# Define the setter of the 'name' property.
@layerToDisplay.setter
@layerToDisplay.setter # type: ignore # mypy bug #9911
def layerToDisplay(self, data_layer_str):
self._layer_to_display = data_layer_str
self.layerToDisplayChanged.emit()
Expand All @@ -141,7 +141,7 @@ def dateToDisplay(self):
else:
return self._date_to_display

@dateToDisplay.setter
@dateToDisplay.setter # type: ignore # mypy bug #9911
def dateToDisplay(self, new_date):
self._date_to_display = new_date.strftime(self._format_str)
self.dateToDisplayChanged.emit(self._date_to_display)
Expand Down Expand Up @@ -219,7 +219,8 @@ def __init__(self, *args, timestamps: List[QDateTime], **kwargs):
super().__init__(*args, **kwargs)
self._format_str = DEFAULT_TIME_FORMAT
self.timestamps = timestamps # sets self._timestamps
self.currentTimestamp = None # sets self._current_timestamp

self._current_timestamp = self._format_str.replace("%", "")

@pyqtProperty("QVariantList", notify=modelChanged)
def model(self):
Expand All @@ -240,7 +241,7 @@ def at(self, i):
def currentTimestamp(self):
return self._current_timestamp

@currentTimestamp.setter
@currentTimestamp.setter # type: ignore # mypy bug #9911
def currentTimestamp(self, new_date):
self._current_timestamp = new_date.strftime(self._format_str) if new_date else self._format_str.replace("%", "")
self.currentTimestampChanged.emit(self._current_timestamp)
Expand All @@ -249,15 +250,6 @@ def currentTimestamp(self, new_date):
def timestamps(self):
return self._timestamps

def clear(self):
"""Set the two corresponding properties which has to do something with the timestamps to None.
The purpose of this is to give a possibility to return to a similar state like
when TimeBaseModel was initialized."""
self.timestamps = None
self.currentTimestamp = None
self.returnToInitialState.emit()

@timestamps.setter
def timestamps(self, timestamps):
self.layoutAboutToBeChanged.emit()
Expand All @@ -271,6 +263,15 @@ def timestamps(self, timestamps):
self.layoutChanged.emit()
self.timebaseChanged.emit()

def clear(self):
"""Set the two corresponding properties which has to do something with the timestamps to None.
The purpose of this is to give a possibility to return to a similar state like
when TimeBaseModel was initialized."""
self.timestamps = None
self.currentTimestamp = None
self.returnToInitialState.emit()

@staticmethod
def _get_default_qdts(steps=5):
"""Generate default QDateTime steps.
Expand Down

0 comments on commit e825d3b

Please sign in to comment.