From c76012262be73c2e6127c29749080b60b1d19bb2 Mon Sep 17 00:00:00 2001 From: bcapuano Date: Sun, 5 Nov 2023 12:48:12 -0500 Subject: [PATCH] Added more explcit typing to from_unicode and changed to have one return --- src/icalendar/parser_tools.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/icalendar/parser_tools.py b/src/icalendar/parser_tools.py index 434f42d2..45c0c238 100644 --- a/src/icalendar/parser_tools.py +++ b/src/icalendar/parser_tools.py @@ -1,8 +1,10 @@ +from typing import Any + SEQUENCE_TYPES = (list, tuple) DEFAULT_ENCODING = 'utf-8' -def from_unicode(value, encoding='utf-8') -> bytes: +def from_unicode(value: Any, encoding='utf-8') -> bytes: """ Converts a value to bytes, even if it already is bytes :param value: The value to convert @@ -10,10 +12,10 @@ def from_unicode(value, encoding='utf-8') -> bytes: :return: The bytes representation of the value """ if isinstance(value, bytes): - return value + value = value elif isinstance(value, str): try: - return value.encode(encoding) + value = value.encode(encoding) except UnicodeEncodeError: value = value.encode('utf-8', 'replace') return value