From 63e4075affc29169f2967b63b56d2f00ec988732 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 12:07:40 +0300 Subject: [PATCH 1/4] helpers::_make_get_default_encoding_func is updated (pylance) - [del] Helpers::_make_get_default_encoding_func - [add] helpers::_make_get_default_encoding_func() -> typing.Callable --- src/helpers.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/helpers.py b/src/helpers.py index 19f2972..501eb6c 100644 --- a/src/helpers.py +++ b/src/helpers.py @@ -13,18 +13,18 @@ def encode(self, *args, **kwargs) -> _BinDataBox: return self -class Helpers: - @staticmethod - def _make_get_default_encoding_func(): - # locale.getencoding is added in Python 3.11 - if hasattr(locale, 'getencoding'): - return locale.getencoding +def _make_get_default_encoding_func() -> typing.Callable: + # locale.getencoding is added in Python 3.11 + if hasattr(locale, 'getencoding'): + return locale.getencoding - # It must exist - return locale.getpreferredencoding + # It must exist + return locale.getpreferredencoding + +class Helpers: # Prepared pointer on function to get a name of system codepage - _get_default_encoding_func = _make_get_default_encoding_func.__func__() + _get_default_encoding_func = _make_get_default_encoding_func() @staticmethod def get_default_encoding(): From 20cf88c4a7a0a7b1895d6f11f785d1dc1e1a102d Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 12:58:35 +0300 Subject: [PATCH 2/4] LocalOperations::_run_command__generic is updated (pylance) --- src/local_ops.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/local_ops.py b/src/local_ops.py index aaa5ac8..796ad6e 100644 --- a/src/local_ops.py +++ b/src/local_ops.py @@ -386,7 +386,7 @@ def _run_command__generic( text=get_process and (encoding is not None), encoding=encoding if get_process else None, **extParams, - ) + ) # type: subprocess.Popen[typing.Any] assert process is not None assert isinstance(process, subprocess.Popen) if get_process: @@ -400,10 +400,16 @@ def _run_command__generic( assert type(output) is bytes assert type(error) is bytes - if encoding: - output = output.decode(encoding) - error = error.decode(encoding) - return process.returncode, output, error + if not encoding: + return process.returncode, output, error + + output_s = output.decode(encoding) + error_s = error.decode(encoding) + + assert type(output_s) is str + assert type(error_s) is str + assert type(process.returncode) is int + return process.returncode, output_s, error_s def _run_command( self, From f22ab4d9cd6b48fe88afbd8f6d736ae990298537 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 13:29:53 +0300 Subject: [PATCH 3/4] LocalOperations::write is updated (pylance) New private methods are added: - _write_binary - _write_text --- src/local_ops.py | 88 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/src/local_ops.py b/src/local_ops.py index 796ad6e..7e59c89 100644 --- a/src/local_ops.py +++ b/src/local_ops.py @@ -847,7 +847,6 @@ def write( encoding: Code page of text data. """ assert type(filename) is str - assert encoding is None or type(encoding) is str assert data is not None assert type(data) in [str, bytes, list] assert type(truncate) is bool @@ -855,26 +854,95 @@ def write( assert type(read_and_write) is bool assert encoding is None or type(encoding) is str + if binary: + return self._write_binary( + filename, + data, + truncate, + read_and_write, + encoding, + ) + + return self._write_text( + filename, + data, + truncate, + read_and_write, + encoding, + ) + + def _write_binary( + self, + filename: str, + data: OsOperations.T_WRITE_DATA, + truncate: bool, + read_and_write: bool, + encoding: typing.Optional[str], + ) -> None: + assert type(filename) is str + assert data is not None + assert type(data) in [str, bytes, list] + assert type(truncate) is bool + assert type(read_and_write) is bool + assert encoding is None or type(encoding) is str + if not encoding: encoding = get_default_encoding() - mode = "w" if truncate else "a" + file = open( + filename, + "wb" if truncate else "ab", + ) + assert file is not None - # If it is a bytes str or list - if binary: - mode += "b" + with file: + if isinstance(data, list): + for s in data: + data2 = __class__._prepare_data_to_write(s, True, encoding) + assert type(data2) is bytes + file.write(data2) + continue + else: + data2 = __class__._prepare_data_to_write(data, True, encoding) + assert type(data2) is bytes + file.write(data2) + return + + def _write_text( + self, + filename: str, + data: OsOperations.T_WRITE_DATA, + truncate: bool, + read_and_write: bool, + encoding: typing.Optional[str], + ) -> None: + assert type(filename) is str + assert data is not None + assert type(data) in [str, bytes, list] + assert type(truncate) is bool + assert type(read_and_write) is bool + assert encoding is None or type(encoding) is str - assert type(mode) is str - assert mode != "" + if not encoding: + encoding = get_default_encoding() + + file = open( + filename, + mode="w" if truncate else "a", + encoding=encoding, + ) + assert file is not None - with open(filename, mode, encoding=None if binary else encoding) as file: + with file: if isinstance(data, list): for s in data: - data2 = __class__._prepare_data_to_write(s, binary, encoding) + data2 = __class__._prepare_data_to_write(s, False, encoding) + assert type(data2) is str file.write(data2) continue else: - data2 = __class__._prepare_data_to_write(data, binary, encoding) + data2 = __class__._prepare_data_to_write(data, False, encoding) + assert type(data2) is str file.write(data2) return From b2e80347f85f3ea03a4610eba3460dbfa7cd7418 Mon Sep 17 00:00:00 2001 From: "d.kovalenko" Date: Mon, 23 Nov 2026 13:38:39 +0300 Subject: [PATCH 4/4] TestOsOpsCommon::test_popen_garbage_collection is updated (pylance) --- tests/test_os_ops_common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_os_ops_common.py b/tests/test_os_ops_common.py index b86bafe..2a085b2 100644 --- a/tests/test_os_ops_common.py +++ b/tests/test_os_ops_common.py @@ -5007,9 +5007,9 @@ def test_popen_garbage_collection( # Запоминаем локальный процесс транспорта, чтобы проверить его смерть в конце if type(controller).__name__ == "LocalProcessController": - local_p = controller._local_process + local_p = getattr(controller, "_local_process") elif type(controller).__name__ == "RemoteProcessController": - local_p = controller._local_process + local_p = getattr(controller, "_local_process") else: raise RuntimeError("Unknown controller type: {}.".format( type(controller).__name__,