diff --git a/src/octoprint/comm/job/__init__.py b/src/octoprint/comm/job/__init__.py index 79192c39b..b3d3843b5 100644 --- a/src/octoprint/comm/job/__init__.py +++ b/src/octoprint/comm/job/__init__.py @@ -34,7 +34,7 @@ class Printjob(ProtocolListener, ListenerAware, metaclass=ABCMeta): if event_data is None: event_data = {} - super(Printjob, self).__init__() + super().__init__() self._logger = logging.getLogger(__name__) self._start = None self._protocol = None @@ -284,7 +284,7 @@ class LocalFilePrintjob(StoragePrintjob): def cancel(self, error=False, user=None, tags=None, **kwargs): self._cancel_pos = self.pos - super(LocalFilePrintjob, self).cancel(error=error, user=user, tags=tags, **kwargs) + super().cancel(error=error, user=user, tags=tags, **kwargs) def get_next(self): from octoprint.util import to_unicode @@ -339,11 +339,10 @@ class LocalFilePrintjob(StoragePrintjob): from octoprint.util import bom_aware_open with bom_aware_open(self._path, encoding=self._encoding, error="replace") as f: - for line in f.readline(): - yield line + yield from f.readline() def reset_job(self, success=True): - super(LocalFilePrintjob, self).reset_job(success=success) + super().reset_job(success=success) self.close() self._pos = self._read_lines = 0 diff --git a/src/octoprint/comm/job/gcode.py b/src/octoprint/comm/job/gcode.py index 40a436e79..bea9cf1cb 100644 --- a/src/octoprint/comm/job/gcode.py +++ b/src/octoprint/comm/job/gcode.py @@ -54,7 +54,7 @@ class LocalGcodeStreamjob(LocalGcodeFilePrintjob, CopyJobMixin): ) def __init__(self, remote, *args, **kwargs): - super(LocalGcodeStreamjob, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self._remote = remote @property @@ -62,25 +62,21 @@ class LocalGcodeStreamjob(LocalGcodeFilePrintjob, CopyJobMixin): return self._remote def process(self, protocol, position=0, user=None, tags=None, **kwargs): - super(LocalGcodeStreamjob, self).process( - protocol, position=position, user=user, tags=tags, **kwargs - ) + super().process(protocol, position=position, user=user, tags=tags, **kwargs) self._protocol.record_file(self._remote) def process_job_done(self, user=None, tags=None, **kwargs): self._protocol.stop_recording_file() - super(LocalGcodeStreamjob, self).process_job_done(user=user, tags=tags, **kwargs) + super().process_job_done(user=user, tags=tags, **kwargs) def process_job_failed(self, **kwargs): self._protocol.stop_recording_file() - super(LocalGcodeStreamjob, self).process_job_failed(**kwargs) + super().process_job_failed(**kwargs) def process_job_cancelled(self, user=None, tags=None, **kwargs): self._protocol.stop_recording_file() self._protocol.delete_file(self.remote) - super(LocalGcodeStreamjob, self).process_job_cancelled( - user=user, tags=tags, **kwargs - ) + super().process_job_cancelled(user=user, tags=tags, **kwargs) def can_process(self, protocol): from octoprint.comm.protocol import ( diff --git a/src/octoprint/comm/job/sdcard.py b/src/octoprint/comm/job/sdcard.py index fc369c425..4e8098df1 100644 --- a/src/octoprint/comm/job/sdcard.py +++ b/src/octoprint/comm/job/sdcard.py @@ -74,11 +74,11 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener): self._protocol.start_file_print_status_monitor() def pause(self, user=None, tags=None, **kwargs): - super(SDFilePrintjob, self).pause(user=user, tags=tags, **kwargs) + super().pause(user=user, tags=tags, **kwargs) self._protocol.pause_file_print(user=user, tags=tags, part_of_job=True, **kwargs) def resume(self, user=None, tags=None, **kwargs): - super(SDFilePrintjob, self).resume(user=user, tags=tags, **kwargs) + super().resume(user=user, tags=tags, **kwargs) self._protocol.resume_file_print(user=user, tags=tags, part_of_job=True, **kwargs) def on_protocol_sd_status(self, protocol, pos, total): @@ -103,7 +103,7 @@ class SDFilePrintjob(StoragePrintjob, FileAwareProtocolListener): self._protocol.resume_file_print(**kwargs) def reset_job(self, success=True): - super(SDFilePrintjob, self).reset_job(success=success) + super().reset_job(success=success) self._active = False self._last_pos = None self._size = None diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index 278b6b743..601212562 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -339,10 +339,10 @@ class ReprapGcodeProtocol( ), advanced=True, ), - defaults=dict( - (f.key, dict((key, getattr(f, key)) for key in f.overridable)) + defaults={ + f.key: {key: getattr(f, key) for key in f.overridable} for f in all_flavors() - ), + }, default="standard", ), ParamGroup( @@ -688,7 +688,7 @@ class ReprapGcodeProtocol( @classmethod def get_attributes_starting_with(cls, prefix): - return dict((x, getattr(cls, x)) for x in dir(cls) if x.startswith(prefix)) + return {x: getattr(cls, x) for x in dir(cls) if x.startswith(prefix)} def __init__(self, flavor=None, *args, **kwargs): super().__init__(*args, **kwargs) @@ -936,7 +936,7 @@ class ReprapGcodeProtocol( self._sending_thread.daemon = True self._sending_thread.start() - super(ReprapGcodeProtocol, self).connect( + super().connect( transport, transport_args=transport_args, transport_kwargs=transport_kwargs ) @@ -1716,19 +1716,19 @@ class ReprapGcodeProtocol( ##~~ Transport logging def on_transport_log_message(self, transport, data): - super(ReprapGcodeProtocol, self).on_transport_log_message(transport, data) + super().on_transport_log_message(transport, data) self._terminal_log.append( self.LOG_PREFIX_MSG + to_unicode(data.strip(), errors="replace") ) def on_transport_log_received_data(self, transport, data): - super(ReprapGcodeProtocol, self).on_transport_log_received_data(transport, data) + super().on_transport_log_received_data(transport, data) self._terminal_log.append( self.LOG_PREFIX_RX + to_unicode(data.strip(), errors="replace") ) def on_transport_log_sent_data(self, transport, data): - super(ReprapGcodeProtocol, self).on_transport_log_sent_data(transport, data) + super().on_transport_log_sent_data(transport, data) self._terminal_log.append( self.LOG_PREFIX_TX + to_unicode(data.strip(), errors="replace") ) diff --git a/src/octoprint/comm/protocol/reprap/commands/atcommand.py b/src/octoprint/comm/protocol/reprap/commands/atcommand.py index 094bc7d9c..ca2cd407a 100644 --- a/src/octoprint/comm/protocol/reprap/commands/atcommand.py +++ b/src/octoprint/comm/protocol/reprap/commands/atcommand.py @@ -26,7 +26,7 @@ class AtCommand(Command): def __init__(self, line, atcommand, parameters, **kwargs): self.atcommand = atcommand self.parameters = parameters - super(AtCommand, self).__init__(line, **kwargs) + super().__init__(line, **kwargs) def __repr__(self): return "AtCommand({!r},{!r},{!r},type={!r},tags={}".format( diff --git a/src/octoprint/comm/protocol/reprap/commands/gcode.py b/src/octoprint/comm/protocol/reprap/commands/gcode.py index 219a8d721..b8fe1c837 100644 --- a/src/octoprint/comm/protocol/reprap/commands/gcode.py +++ b/src/octoprint/comm/protocol/reprap/commands/gcode.py @@ -108,7 +108,7 @@ class GcodeCommand(Command): else: line = self.original - super(GcodeCommand, self).__init__(line, type=command_type, tags=tags) + super().__init__(line, type=command_type, tags=tags) self._repr = self._to_repr() diff --git a/src/octoprint/comm/protocol/reprap/scripts.py b/src/octoprint/comm/protocol/reprap/scripts.py index ccf065417..4724a9dbc 100644 --- a/src/octoprint/comm/protocol/reprap/scripts.py +++ b/src/octoprint/comm/protocol/reprap/scripts.py @@ -13,10 +13,10 @@ class GcodeScript(Script): raise UnknownScript(name) return lines - super(GcodeScript, self).__init__(name, renderer, context=context) + super().__init__(name, renderer, context=context) def render(self, context=None): - script = super(GcodeScript, self).render(context) + script = super().render(context) return list( filter( lambda x: x is not None and x.strip() != "", diff --git a/src/octoprint/comm/protocol/reprap/util/__init__.py b/src/octoprint/comm/protocol/reprap/util/__init__.py index e18289e7c..44156c97b 100644 --- a/src/octoprint/comm/protocol/reprap/util/__init__.py +++ b/src/octoprint/comm/protocol/reprap/util/__init__.py @@ -284,7 +284,7 @@ class PositionRecord: attrs = self._standard_attrs | set( [key for key in dir(self) if self.valid_e(key)] ) - return dict((attr, getattr(self, attr)) for attr in attrs) + return {attr: getattr(self, attr) for attr in attrs} class TemperatureRecord: diff --git a/src/octoprint/comm/transport/__init__.py b/src/octoprint/comm/transport/__init__.py index e5de351aa..71d9b0cfa 100644 --- a/src/octoprint/comm/transport/__init__.py +++ b/src/octoprint/comm/transport/__init__.py @@ -131,7 +131,7 @@ class Transport(ListenerAware): return [] def __init__(self, *args, **kwargs): - super(Transport, self).__init__() + super().__init__() self._logger = logging.getLogger(__name__) self._state = TransportState.DISCONNECTED @@ -261,10 +261,10 @@ class TransportWrapper(ListenerAware): def f(*args, **kwargs): # replace references to self.transport with self args = [self if arg == self.transport else arg for arg in args] - kwargs = dict( - (key, self if value == self.transport else value) + kwargs = { + key: self if value == self.transport else value for key, value in kwargs.items() - ) + } # forward self.notify_listeners(name, *args, **kwargs) @@ -350,7 +350,7 @@ class PushingTransportWrapper(TransportWrapper): def __init__( self, transport, name=b"PushingTransportWrapper.receiver_loop", timeout=None ): - super(PushingTransportWrapper, self).__init__(transport) + super().__init__(transport) self.name = name self.timeout = timeout diff --git a/src/octoprint/comm/transport/serialtransport.py b/src/octoprint/comm/transport/serialtransport.py index 28d394c0e..b9c16f4d5 100644 --- a/src/octoprint/comm/transport/serialtransport.py +++ b/src/octoprint/comm/transport/serialtransport.py @@ -159,7 +159,7 @@ class SerialTransport(Transport): ) def __init__(self, *args, **kwargs): - super(SerialTransport, self).__init__() + super().__init__() self.serial_factory = kwargs.get("serial_factory", None) diff --git a/src/octoprint/comm/transport/sockettransport.py b/src/octoprint/comm/transport/sockettransport.py index 4bef0d806..77a06f924 100644 --- a/src/octoprint/comm/transport/sockettransport.py +++ b/src/octoprint/comm/transport/sockettransport.py @@ -18,7 +18,7 @@ class TcpTransport(Transport): return [TextType("host", "Host"), IntegerType("port", "Port", min=1, max=65535)] def __init__(self): - super(TcpTransport, self).__init__() + super().__init__() self._socket = None diff --git a/src/octoprint/comm/util/parameters.py b/src/octoprint/comm/util/parameters.py index 79cf15374..c79188c77 100644 --- a/src/octoprint/comm/util/parameters.py +++ b/src/octoprint/comm/util/parameters.py @@ -29,7 +29,7 @@ def get_param_defaults(options): def get_param_dict(data, options): - options_by_name = dict((option.name, option) for option in options) + options_by_name = {option.name: option for option in options} result = {} for key, value in data.items(): @@ -284,7 +284,7 @@ class ParamGroup(ParamType): def convert(self, value): if not isinstance(value, dict): raise ValueError("value {!r} must be a dict".format(value)) - return dict((k, v.convert()) for k, v in value.items()) + return {k: v.convert() for k, v in value.items()} class Value: diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 2c0acbe18..28dbf8166 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -701,7 +701,7 @@ class Printer( if len(axes) != len(validated_axes): raise ValueError("axes contains invalid axes: {axes}".format(axes=axes)) - kwargs = dict((axes, True) for axes in validated_axes) + kwargs = {axes: True for axes in validated_axes} self._protocol.home(**kwargs) def extrude(self, amount, speed=None, *args, **kwargs): diff --git a/tests/comm/__init__.py b/tests/comm/__init__.py index fcdb84d66..e2ec39f45 100644 --- a/tests/comm/__init__.py +++ b/tests/comm/__init__.py @@ -14,7 +14,7 @@ from octoprint.util import monotonic_time, to_bytes class TestTransport(Transport): def __init__(self, *args, **kwargs): - super(TestTransport, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.outgoing = bytearray() self.incoming = [] diff --git a/tests/plugin/test_settings.py b/tests/plugin/test_settings.py index 10a745039..28423508c 100644 --- a/tests/plugin/test_settings.py +++ b/tests/plugin/test_settings.py @@ -142,7 +142,7 @@ class SettingsTestCase(unittest.TestCase): ], "some_value", ), - dict(), + {}, "set", ), ( @@ -153,7 +153,7 @@ class SettingsTestCase(unittest.TestCase): ], "some_value", ), - dict(force=True), + {"force": True}, "set", ), ( @@ -164,7 +164,7 @@ class SettingsTestCase(unittest.TestCase): ], 23, ), - dict(), + {}, "setInt", ), ( @@ -175,7 +175,7 @@ class SettingsTestCase(unittest.TestCase): ], 23, ), - dict(force=True), + {"force": True}, "setInt", ), ( @@ -186,7 +186,7 @@ class SettingsTestCase(unittest.TestCase): ], 2.3, ), - dict(), + {}, "setFloat", ), ( @@ -197,7 +197,7 @@ class SettingsTestCase(unittest.TestCase): ], 2.3, ), - dict(force=True), + {"force": True}, "setFloat", ), ( @@ -208,7 +208,7 @@ class SettingsTestCase(unittest.TestCase): ], True, ), - dict(), + {}, "setBoolean", ), ( @@ -219,7 +219,7 @@ class SettingsTestCase(unittest.TestCase): ], True, ), - dict(force=True), + {"force": True}, "setBoolean", ), )