Explicitly specify encoding
The update to pylint means we were failing because open() doesn't specify the encoding everywhere. I have now specified utf-8 everywhere. This was patchy before, and is default behaviour on the Pi. There's a slim chance it will cause some issues on Windows, but that shouldn't affect anyone outside the developers. I've also ignored a couple of new spurious warnings, and explicitly ignored some unused variables.
This commit is contained in:
parent
9b7fba55b6
commit
a9fff24848
11 changed files with 16 additions and 15 deletions
|
|
@ -261,10 +261,10 @@ def generate_openapi():
|
|||
if fname.endswith(".json"):
|
||||
import json
|
||||
|
||||
with open(fname, "w") as fd:
|
||||
with open(fname, "w", encoding="utf-8") as fd:
|
||||
json.dump(labthing.spec.to_dict(), fd)
|
||||
else:
|
||||
with open(fname, "w") as fd:
|
||||
with open(fname, "w", encoding="utf-8") as fd:
|
||||
fd.write(labthing.spec.to_yaml())
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -245,7 +245,7 @@ def extension_action(args=None):
|
|||
# Run the action
|
||||
return func(self.extension, **arguments)
|
||||
|
||||
def get(self, *args, **kwargs): # pylint: disable=useless-super-delegation
|
||||
def get(self, *args, **kwargs): # pylint: disable=useless-super-delegation,arguments-differ
|
||||
# Explicitly wrap the `get` method to allow us to add a docstring
|
||||
return super().get(*args, **kwargs)
|
||||
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ class CSMExtension(BaseExtension):
|
|||
"linear_calibration_y": cal_y,
|
||||
}
|
||||
|
||||
with open(CSM_DATAFILE_PATH, "w") as f:
|
||||
with open(CSM_DATAFILE_PATH, "w", encoding="utf-8") as f:
|
||||
json.dump(data, f, cls=JSONEncoder)
|
||||
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ def init_default_extensions(extension_dir: str):
|
|||
create_file(default_ext_path)
|
||||
|
||||
logging.info("Populating %s...", (default_ext_path))
|
||||
with open(default_ext_path, "w") as outfile:
|
||||
with open(default_ext_path, "w", encoding="utf-8") as outfile:
|
||||
outfile.write(_DEFAULT_EXTENSION_INIT)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class FrameStream(io.BytesIO):
|
|||
t: Optional[Type[BaseException]],
|
||||
value: Optional[BaseException],
|
||||
traceback: Optional[TracebackType],
|
||||
) -> Optional[bool]:
|
||||
) -> None:
|
||||
self.stop_tracking()
|
||||
return super().__exit__(t, value, traceback)
|
||||
|
||||
|
|
|
|||
|
|
@ -120,7 +120,8 @@ class CaptureObject(object):
|
|||
logging.debug("Finished writing to disk %s", self.file)
|
||||
|
||||
def open(self, mode):
|
||||
return open(self.file, mode)
|
||||
# We don't specify an encoding because this will be a binary file.
|
||||
return open(self.file, mode) # pylint: disable=unspecified-encoding
|
||||
|
||||
def split_file_path(self, filepath: str):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ def load_json_file(config_path) -> dict:
|
|||
|
||||
logging.info("Loading %s...", config_path)
|
||||
|
||||
with open(config_path) as config_file:
|
||||
with open(config_path, encoding="utf-8") as config_file:
|
||||
try:
|
||||
config_data = json.load(config_file)
|
||||
except json.decoder.JSONDecodeError as e:
|
||||
|
|
@ -112,7 +112,7 @@ def save_json_file(config_path: str, config_dict: dict):
|
|||
logging.info("Saving %s...", config_path)
|
||||
logging.debug(config_dict)
|
||||
|
||||
with open(config_path, "w") as outfile:
|
||||
with open(config_path, "w", encoding="utf-8") as outfile:
|
||||
json.dump(config_dict, outfile, cls=JSONEncoder, indent=2, sort_keys=True)
|
||||
|
||||
|
||||
|
|
@ -150,7 +150,7 @@ def initialise_file(config_path, populate: str = "{}\n"):
|
|||
create_file(config_path)
|
||||
|
||||
logging.info("Populating %s...", (config_path))
|
||||
with open(config_path, "w") as outfile:
|
||||
with open(config_path, "w", encoding="utf-8") as outfile:
|
||||
outfile.write(populate)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ def main():
|
|||
|
||||
try:
|
||||
import picamerax
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
except Exception as _: # pylint: disable=W0703
|
||||
error_sources.append(PICAMERA_IMPORT_ERROR)
|
||||
else:
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ def main():
|
|||
# Try connecting on the specified port
|
||||
try:
|
||||
stage = Sangaboard(stage_port)
|
||||
except FileNotFoundError as e:
|
||||
except FileNotFoundError as _:
|
||||
if stage_port:
|
||||
error_sources.append(
|
||||
ErrorSource(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue