Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ def encode(self, *args, **kwargs) -> _BinDataBox:

def _make_get_default_encoding_func() -> typing.Callable:
# locale.getencoding is added in Python 3.11
if hasattr(locale, 'getencoding'):
return locale.getencoding
func = getattr(locale, 'getencoding', None)
if func is not None:
assert isinstance(func, typing.Callable)
return func

# It must exist
return locale.getpreferredencoding
Expand All @@ -27,7 +29,7 @@ class Helpers:
_get_default_encoding_func = _make_get_default_encoding_func()

@staticmethod
def get_default_encoding():
def get_default_encoding() -> str:
#
# Original idea/source was:
#
Expand Down
9 changes: 4 additions & 5 deletions src/os_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from .types import T_OS_EXEC_INPUT
from .types import T_OS_EXEC_ENV
from .raise_error import RaiseError
from .helpers import Helpers


import locale
import typing
import signal as os_signal
import subprocess
Expand Down Expand Up @@ -38,10 +39,8 @@ def __init__(
return


def get_default_encoding():
if not hasattr(locale, 'getencoding'):
locale.getencoding = locale.getpreferredencoding
return locale.getencoding() or 'UTF-8'
def get_default_encoding() -> str:
return Helpers.get_default_encoding()


class OsProcessController:
Expand Down
Loading