2
This commit is contained in:
@ -16,11 +16,15 @@ You should have received a copy of the GNU General Public License along with
|
||||
this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
from typeguard import typechecked
|
||||
|
||||
|
||||
def is_string_blank(string: str):
|
||||
@typechecked
|
||||
def is_string_blank(string: str) -> bool:
|
||||
"""
|
||||
Check if a string equals to a blank string after stripped.
|
||||
|
||||
@ -37,14 +41,11 @@ def is_string_blank(string: str):
|
||||
False
|
||||
"""
|
||||
|
||||
if not isinstance(string, str):
|
||||
msg = "A `str` object is expected"
|
||||
raise TypeError(msg)
|
||||
|
||||
return string.strip() == ""
|
||||
|
||||
|
||||
def blank_str_to_none(string: str):
|
||||
@typechecked
|
||||
def blank_str_to_none(string: str | None) -> str | None:
|
||||
"""
|
||||
Convert a blank string (see :func:`~is_string_blank`) to None, otherwise return the
|
||||
original string.
|
||||
@ -68,14 +69,11 @@ def blank_str_to_none(string: str):
|
||||
if string is None:
|
||||
return None
|
||||
|
||||
if not isinstance(string, str):
|
||||
msg = "A `str` object is expected"
|
||||
raise TypeError(msg)
|
||||
|
||||
return None if is_string_blank(string) else string
|
||||
|
||||
|
||||
def replace_single_newline(text: Optional[str]):
|
||||
@typechecked
|
||||
def replace_single_newline(text: str | None) -> str | None:
|
||||
if text is None:
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user