Skip to content

Commit

Permalink
Minor code cleanup, pylint directives
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexShkarin committed Dec 25, 2021
1 parent 2b90916 commit e36d732
Show file tree
Hide file tree
Showing 75 changed files with 216 additions and 210 deletions.
5 changes: 5 additions & 0 deletions .pylintdict
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ bytestring
andor
roi
setpoint
setpoints
dll
ini
sdk
Expand Down Expand Up @@ -390,3 +391,7 @@ TQD
TPA
KPA
stylesheet
Leybold
ITR
KJL
KCube
13 changes: 7 additions & 6 deletions pylablib/core/devio/comm_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ def write(self, data, flush=True, read_echo=False, read_echo_delay=0, read_echo_
"""
Write data to the device.
If ``flush==True``, flush the write buffer.
If ``read_echo==True``, wait for `read_echo_delay` seconds and then perform :func:`readline` (`read_echo_lines` times).
`flush` parameter is ignored.
"""
self._log("write",data)
data=py3.as_builtin_bytes(data)
Expand Down Expand Up @@ -653,7 +653,7 @@ def _read_terms(self, terms=(), timeout=None, error_on_timeout=True):
if result.endswith(t):
return result
@logerror
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True):
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True): # pylint: disable=arguments-differ
"""
Read a single line from the device.
Expand Down Expand Up @@ -886,7 +886,7 @@ def _read_terms(self, terms=(), timeout=None, error_on_timeout=True):
if result.endswith(t):
return result
@logerror
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True):
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True): # pylint: disable=arguments-differ
"""
Read a single line from the device.
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def _read_terms(self, terms=(), read_block_size=65536, timeout=None, error_on_ti
if result.endswith(t):
return result
@logerror
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True):
def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_timeout=True): # pylint: disable=arguments-differ
"""
Read a single line from the device.
Expand All @@ -1295,7 +1295,7 @@ def readline(self, remove_term=True, timeout=None, skip_empty=True, error_on_tim
return self._to_datatype(result)
@logerror
@reraise
def read(self, size=None, max_read_size=65536):
def read(self, size=None, max_read_size=65536): # pylint: disable=arguments-differ
"""
Read data from the device.
Expand Down Expand Up @@ -1331,11 +1331,12 @@ def read_multichar_term(self, term, remove_term=True, timeout=None, error_on_tim
return self._to_datatype(result)
@logerror
@reraise
def write(self, data, read_echo=False, read_echo_delay=0, read_echo_lines=1):
def write(self, data, flush=True, read_echo=False, read_echo_delay=0, read_echo_lines=1):
"""
Write data to the device.
If ``read_echo==True``, wait for `read_echo_delay` seconds and then perform :func:`readline` (`read_echo_lines` times).
`flush` parameter is ignored.
"""
self._log("write",data)
data=py3.as_builtin_bytes(data)
Expand Down
14 changes: 7 additions & 7 deletions pylablib/core/fileio/dict_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _prepare_desc_data(self):
return desc, data

@classmethod
def from_dict(cls, dict_ptr, loc, out_type="pandas"):
def from_dict(cls, dict_ptr, loc, out_type="pandas"): # pylint: disable=arguments-differ
"""
Convert a dictionary branch to a specific DictionaryEntry object.
Expand Down Expand Up @@ -564,15 +564,15 @@ def from_dict(cls, dict_ptr, loc):
def get_preamble(self):
"""Generate preamble (dictionary with supplementary data which allows to load the data from the file)"""
return {}
def save_file(self, loc_file):
def save_file(self, location_file):
"""
Save stored data into the given location.
Virtual method, should be overloaded in subclasses
"""
raise NotImplementedError("IExternalFileDictionaryEntry.save_file")
@classmethod
def load_file(cls, loc_file, preamble):
def load_file(cls, location_file, preamble):
"""
Load stored data from the given location, using the supplied preamble.
Expand All @@ -599,14 +599,14 @@ def __init__(self, data, name="", force_name=True, dtype=None):
def get_preamble(self):
"""Generate preamble (dictionary with supplementary data which allows to load the data from the file)"""
return {"shape":self.data.shape,"dtype":self.data.dtype.str}
def save_file(self, loc_file):
def save_file(self, location_file):
"""Save stored data into the given location"""
with loc_file.open("wb") as stream:
with location_file.open("wb") as stream:
self.data.tofile(stream)
@classmethod
def load_file(cls, loc_file, preamble):
def load_file(cls, location_file, preamble):
"""Load stored data from the given location, using the supplied preamble"""
with loc_file.open("rb") as stream:
with location_file.open("rb") as stream:
return np.fromfile(stream,dtype=preamble["dtype"]).reshape(preamble["shape"])
IExternalFileDictionaryEntry.add_file_format(ExternalNumpyDictionaryEntry)

Expand Down
12 changes: 6 additions & 6 deletions pylablib/core/fileio/savefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _write_table_inline(self, stream, table):
line=self.inline_delimiters.join(line)
self.write_line(stream,line)
self.write_line(stream,"## Table end ##")
def write_data(self, loc_file, data):
def write_data(self, location_file, data):
"""
Write data to a Dictionary file.
Expand All @@ -204,8 +204,8 @@ def write_data(self, loc_file, data):
"""
if not dictionary.is_dictionary(data):
raise ValueError("format '{0}' can't save data {1}".format(self.format_name,data))
loc=loc_file.loc
stream=loc_file.stream
loc=location_file.loc
stream=location_file.stream
table_builder=dict_entry.table_entry_builder(self.table_format)
for path, value in data.iternodes(ordered=True,to_visit="leafs",include_path=True):
if string_utils.is_convertible(value):
Expand All @@ -224,7 +224,7 @@ def write_data(self, loc_file, data):
br=data.detach(rel_path)
data.add_entry(rel_path,d,branch_option="attach")
try:
self.write_data(loc_file,data.branch_pointer(rel_path))
self.write_data(location_file,data.branch_pointer(rel_path))
finally:
data.detach(rel_path)
data.add_entry(rel_path,br,branch_option="attach")
Expand All @@ -234,7 +234,7 @@ def write_data(self, loc_file, data):


class IBinaryOutputFileFormat(IOutputFileFormat): # pylint: disable=abstract-method
def get_preamble(self, loc_file, data): # pylint: disable=unused-argument
def get_preamble(self, location_file, data): # pylint: disable=unused-argument
return dictionary.Dictionary()


Expand All @@ -256,7 +256,7 @@ def get_dtype(self, table):
return np.asarray(table).dtype.newbyteorder("<").str
else:
return self.dtype
def get_preamble(self, loc_file, data):
def get_preamble(self, location_file, data):
"""
Generate a preamble (dictionary describing the file format).
Expand Down
1 change: 1 addition & 0 deletions pylablib/core/gui/value_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,7 @@ def add_virtual_element(self, name, value=None, multivalued=False, add_indicator
Doesn't correspond to any actual widget, but behaves very similarly from the application point of view
(its value can be set or read, it has on-change events, it can have indicator).
The element value is simply stored on set and retrieved on get.
If ``multivalued==True``, the internal value is assumed to be complex, so it is forced to be a :class:`.Dictionary` every time it is set.
If ``add_indicator==True``, add default indicator handler as well.
"""
h=self.add_handler(name,VirtualValueHandler(value,multivalued=multivalued))
Expand Down
11 changes: 6 additions & 5 deletions pylablib/core/gui/widgets/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def add_virtual_element(self, name, value=None, multivalued=False, add_indicator
Doesn't correspond to any actual widget, but behaves very similarly from the application point of view
(its value can be set or read, it has on-change events, it can have indicator).
The element value is simply stored on set and retrieved on get.
If ``multivalued==True``, the internal value is assumed to be complex, so it is forced to be a :class:`.Dictionary` every time it is set.
If ``add_indicator==True``, add default indicator handler as well.
"""
self.gui_values.add_virtual_element(name,value=value,multivalued=multivalued,add_indicator=add_indicator)
Expand Down Expand Up @@ -361,10 +362,10 @@ class IQWidgetContainer(IQLayoutManagedWidget, IQContainer):
Abstract mix-in class, which needs to be added to a class inheriting from ``QWidget``.
Alternatively, one can directly use :class:`QWidgetContainer`, which already inherits from ``QWidget``.
"""
def setup(self, layout="vbox", no_margins=False, name=None):
def setup(self, layout="vbox", no_margins=False, name=None): # pylint: disable=arguments-differ
IQContainer.setup(self,name=name)
IQLayoutManagedWidget.setup(self,layout=layout,no_margins=no_margins)
def add_child(self, name, widget, location=None, gui_values_path=True):
def add_child(self, name, widget, location=None, gui_values_path=True): # pylint: disable=arguments-differ
"""
Add a contained child widget.
Expand Down Expand Up @@ -452,7 +453,7 @@ class QDialogContainer(IQWidgetContainer, QtWidgets.QDialog):

class QGroupBoxContainer(IQWidgetContainer, QtWidgets.QGroupBox):
"""An extension of :class:`IQWidgetContainer` for a ``QGroupBox`` Qt base class"""
def setup(self, caption=None, layout="vbox", no_margins=False, name=None):
def setup(self, caption=None, layout="vbox", no_margins=False, name=None): # pylint: disable=arguments-differ
super().setup(layout=layout,no_margins=no_margins,name=name)
if caption is not None:
self.setTitle(caption)
Expand All @@ -462,9 +463,9 @@ class QScrollAreaContainer(IQContainer, QtWidgets.QScrollArea):
An extension of :class:`IQWidgetContainer` for a ``QScrollArea`` Qt base class.
Due to Qt organization, this container is "intermediate": it contains only a single :class:`QWidgetContainer` widget (named ``"widget"``),
which int turn has all of the standard container traits: layout, multiple widgets, etc.
which in turn has all of the standard container traits: layout, multiple widgets, etc.
"""
def setup(self, layout="vbox", no_margins=False, name=None):
def setup(self, layout="vbox", no_margins=False, name=None): # pylint: disable=arguments-differ
super().setup(name=name)
self.setFrameStyle(QtWidgets.QFrame.NoFrame)
self.setWidgetResizable(True)
Expand Down
14 changes: 8 additions & 6 deletions pylablib/core/gui/widgets/param_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _set_main_layout(self):
super()._set_main_layout()
self.main_layout.setContentsMargins(5,5,5,5)
self.main_layout.setColumnStretch(1,1)
def setup(self, name=None, add_indicator=True, gui_thread_safe=False, cache_values=False, change_focused_control=False):
def setup(self, name=None, add_indicator=True, gui_thread_safe=False, cache_values=False, change_focused_control=False): # pylint: disable=arguments-differ
"""
Setup the table.
Expand Down Expand Up @@ -242,15 +242,17 @@ def remove_widget(self, name):
self.remove_layout_element(par.label)
if par.indicator is not None:
self.remove_layout_element(par.indicator)
def add_virtual_element(self, name, value=None, add_indicator=None):
def add_virtual_element(self, name, value=None, multivalued=False, add_indicator=None):
"""
Add a virtual table element.
Doesn't correspond to any actual widget, but behaves very similarly from the application point of view
(its value can be set or read, it has on-change events, it can have indicator).
The element value is simply stored on set and retrieved on get.
If ``multivalued==True``, the internal value is assumed to be complex, so it is forced to be a :class:`.Dictionary` every time it is set.
If ``add_indicator==True``, add default indicator handler as well.
"""
value_handler=value_handling.VirtualValueHandler(value)
value_handler=value_handling.VirtualValueHandler(value,multivalued=multivalued)
if add_indicator is None:
add_indicator=self.add_indicator
indicator_handler=value_handling.VirtualIndicatorHandler if add_indicator else None
Expand Down Expand Up @@ -508,7 +510,7 @@ def get_value(self, name=None):
def get_all_values(self):
return super().get_all_values()
@controller.gui_thread_method
def set_value(self, name, value, force=False):
def set_value(self, name, value, force=False): # pylint: disable=arguments-differ
"""
Set value of a widget with the given name.
Expand All @@ -527,7 +529,7 @@ def set_value(self, name, value, force=False):
if allow_set:
return super().set_value(name,value)
@controller.gui_thread_method
def set_all_values(self, value, force=False):
def set_all_values(self, value, force=False): # pylint: disable=arguments-differ
"""
Set values of all widgets in the table.
Expand Down Expand Up @@ -579,7 +581,7 @@ def set_all_indicators(self, value, ignore_missing=True):
def update_indicators(self):
return super().update_indicators()

def clear(self, disconnect=False):
def clear(self, disconnect=False): # pylint: disable=arguments-differ
"""
Clear the table (remove all widgets)
Expand Down
8 changes: 4 additions & 4 deletions pylablib/core/thread/callsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def skipped(self):
def failed(self):
"""Check if the call failed"""
return self.get_progress()=="fail"
def get_value_sync(self, timeout=None, default=None, error_on_fail=True, error_on_skip=True, pass_exception=True):
def get_value_sync(self, timeout=None, default=None, error_on_fail=True, error_on_skip=True, pass_exception=True): # pylint: disable=arguments-differ
"""
Wait (with the given `timeout`) for the value passed by the notifier
Expand All @@ -40,7 +40,7 @@ def get_value_sync(self, timeout=None, default=None, error_on_fail=True, error_o
If ``error_on_skip==True`` and the call was skipped (e.g., due to full call queue), raise :exc:`.threadprop.SkippedCallError`; otherwise, return `default`.
If ``pass_exception==True`` and the returned value represents exception, re-raise it in the caller thread; otherwise, return `default`.
"""
res=QThreadNotifier.get_value_sync(self,timeout=timeout)
res=super().get_value_sync(timeout=timeout)
if res is not None:
kind,value=res # pylint: disable=unpacking-non-sequence
if kind=="result":
Expand Down Expand Up @@ -166,7 +166,7 @@ def execute(self, silent=None):
try:
res=("fail",None)
res=("result",self.func(*self.args,**self.kwargs))
except Exception as e:
except Exception as e: # pylint: disable=broad-except
res=("exception",e)
if not (self.silent if silent is None else silent):
raise
Expand Down Expand Up @@ -418,7 +418,7 @@ def has_calls(self):
return bool(self.call_queue)
def __len__(self):
return len(self.call_queue)
def clear(self, close=True):
def clear(self, close=True): # pylint: disable=arguments-differ
"""
Clear the call queue.
Expand Down
8 changes: 4 additions & 4 deletions pylablib/core/thread/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,7 @@ def full_cleanup(*args, **kwargs):
self.start_batch_job(name,period,*(args or []),start_immediate=start_immediate,**(kwargs or {}))
return name

def _get_priority_queue(self, priority, fast=False):
def _get_priority_queue(self, priority):
"""Get the queue with the given priority, creating one if it does not exist"""
if priority not in self._priority_queues:
with self._priority_queues_lock:
Expand Down Expand Up @@ -1958,7 +1958,7 @@ def get_controller(name=None, sync=True, timeout=None, sync_point=None):
"""
if name is None:
return threadprop.current_controller()
def get_controller():
def get_specified_controller():
if isinstance(name,int):
for ctl in _running_threads.values():
if ctl.thread.thread_id==name:
Expand All @@ -1967,14 +1967,14 @@ def get_controller():
raise threadprop.NoControllerThreadError("thread {} is stopped".format(name))
return _running_threads.get(name,None)
with _running_threads_lock:
ctl=get_controller()
ctl=get_specified_controller()
if ctl is None and not sync:
raise threadprop.NoControllerThreadError("thread {} doesn't exist".format(name))
if ctl is not None and sync_point is None:
return ctl
def wait_cond():
with _running_threads_lock:
ctl=get_controller()
ctl=get_specified_controller()
if ctl is not None:
return ctl
thread=_running_threads_notifier.wait_until(wait_cond,timeout=timeout)
Expand Down
6 changes: 3 additions & 3 deletions pylablib/core/thread/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def _check_yappi():


_wall_timer=time.time()
def start(reset=True):
def start(reset=True): # pylint: disable=redefined-outer-name
"""
Start yappi profile logging.
If ``reset==True``, reset the stats.
"""
_check_yappi()
global _wall_timer
global _wall_timer # pylint: disable=global-statement
yappi.set_clock_type("cpu")
yappi.stop()
if reset:
Expand All @@ -33,7 +33,7 @@ def start(reset=True):
def reset():
"""Reset yappi profiling stats"""
_check_yappi()
global _wall_timer
global _wall_timer # pylint: disable=global-statement
yappi.clear_stats()
_wall_timer=time.time()
def stop():
Expand Down
Loading

0 comments on commit e36d732

Please sign in to comment.