diff --git a/.pylintrc b/.pylintrc index c7098a9637..00a4c647c6 100644 --- a/.pylintrc +++ b/.pylintrc @@ -69,7 +69,7 @@ confidence= disable=arguments-renamed, # more readable and clear bad-continuation, bad-whitespace, # differences of opinion with black consider-using-f-string, # unnecesary to convert all str.format() to f strings - consider-using-with, # TODO: investigate / re-enable + consider-using-with, # too verbose, not all resource-allocating operations should have `with` docstring-first-line-empty, # docstrings are more readable duplicate-code, # too verbose fixme, # avoid that to do annotations show up as warnings @@ -78,7 +78,7 @@ disable=arguments-renamed, # more readable and clear no-member, # false positives when variable from external function no-self-use, # too verbose protected-access, # we don't strictly follow the public vs. private convention - raise-missing-from, # TODO: investigate / re-enable + raise-missing-from, # not every exception needs `from`, adding `from None` is too verbose too-few-public-methods, # too verbose too-many-ancestors, # too verbose too-many-arguments, # too verbose @@ -90,7 +90,6 @@ disable=arguments-renamed, # more readable and clear too-many-public-methods, # too verbose too-many-statements, # too verbose unnecessary-pass, # allow for methods with just "pass", for clarity - unspecified-encoding, # TODO: investigate / re-enable # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/qiskit_ibm_runtime/accounts/storage.py b/qiskit_ibm_runtime/accounts/storage.py index 1e59692e96..a3948b61fc 100644 --- a/qiskit_ibm_runtime/accounts/storage.py +++ b/qiskit_ibm_runtime/accounts/storage.py @@ -26,7 +26,7 @@ def save_config(filename: str, name: str, config: dict, overwrite: bool) -> None logger.debug("Save configuration data for '%s' in '%s'", name, filename) _ensure_file_exists(filename) - with open(filename, mode="r") as json_in: + with open(filename, mode="r", encoding="utf-8") as json_in: data = json.load(json_in) if data.get(name) and not overwrite: @@ -35,7 +35,7 @@ def save_config(filename: str, name: str, config: dict, overwrite: bool) -> None f"Set overwrite=True to overwrite." ) - with open(filename, mode="w") as json_out: + with open(filename, mode="w", encoding="utf-8") as json_out: data[name] = config json.dump(data, json_out, sort_keys=True, indent=4) @@ -48,7 +48,7 @@ def read_config( logger.debug("Read configuration data for '%s' from '%s'", name, filename) _ensure_file_exists(filename) - with open(filename) as json_file: + with open(filename, encoding="utf-8") as json_file: data = json.load(json_file) if name is None: return data @@ -67,11 +67,11 @@ def delete_config( logger.debug("Delete configuration data for '%s' from '%s'", name, filename) _ensure_file_exists(filename) - with open(filename, mode="r") as json_in: + with open(filename, mode="r", encoding="utf-8") as json_in: data = json.load(json_in) if name in data: - with open(filename, mode="w") as json_out: + with open(filename, mode="w", encoding="utf-8") as json_out: del data[name] json.dump(data, json_out, sort_keys=True, indent=4) return True @@ -87,5 +87,5 @@ def _ensure_file_exists(filename: str, initial_content: str = "{}") -> None: os.makedirs(os.path.dirname(filename), exist_ok=True) # initialize file - with open(filename, mode="w") as json_file: + with open(filename, mode="w", encoding="utf-8") as json_file: json_file.write(initial_content) diff --git a/qiskit_ibm_runtime/ibm_runtime_service.py b/qiskit_ibm_runtime/ibm_runtime_service.py index 0af7ae805e..80beb5930a 100644 --- a/qiskit_ibm_runtime/ibm_runtime_service.py +++ b/qiskit_ibm_runtime/ibm_runtime_service.py @@ -925,7 +925,7 @@ def upload_program( if "def main(" not in data: # This is the program file - with open(data, "r") as file: + with open(data, "r", encoding="utf-8") as file: data = file.read() try: @@ -957,7 +957,7 @@ def _read_metadata(self, metadata: Optional[Union[Dict, str]] = None) -> Dict: upd_metadata: dict = {} if metadata is not None: if isinstance(metadata, str): - with open(metadata, "r") as file: + with open(metadata, "r", encoding="utf-8") as file: upd_metadata = json.load(file) else: upd_metadata = metadata @@ -1013,7 +1013,7 @@ def update_program( if data: if "def main(" not in data: # This is the program file - with open(data, "r") as file: + with open(data, "r", encoding="utf-8") as file: data = file.read() data = to_base64_string(data) diff --git a/qiskit_ibm_runtime/version.py b/qiskit_ibm_runtime/version.py index 53c037a0df..f3c30983ea 100644 --- a/qiskit_ibm_runtime/version.py +++ b/qiskit_ibm_runtime/version.py @@ -60,7 +60,7 @@ def git_version() -> str: return git_revision -with open(os.path.join(ROOT_DIR, "VERSION.txt"), "r") as version_file: +with open(os.path.join(ROOT_DIR, "VERSION.txt"), "r", encoding="utf-8") as version_file: VERSION = version_file.read().strip() diff --git a/test/test_logger.py b/test/test_logger.py index c4810b0ab6..cb53d453a0 100644 --- a/test/test_logger.py +++ b/test/test_logger.py @@ -165,7 +165,7 @@ def test_log_file(self): ) # Assert the messages were logged. - with open(temp_log_file.name) as file_: + with open(temp_log_file.name, encoding="utf-8") as file_: content_as_str = file_.read() # Check whether the appropriate substrings are in the file. diff --git a/test/test_tutorials.py b/test/test_tutorials.py index 315dd5c389..75c449239e 100644 --- a/test/test_tutorials.py +++ b/test/test_tutorials.py @@ -62,7 +62,7 @@ def _run_notebook(filename): # Open the notebook. file_path = os.path.dirname(os.path.abspath(filename)) - with open(filename) as file_: + with open(filename, encoding="utf-8") as file_: notebook = nbformat.read(file_, as_version=4) with warnings.catch_warnings():