From e39f5e66f4b62a0ef4ee58d8b8e2936b341ad1b7 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani Date: Mon, 10 Jan 2022 12:48:51 +0530 Subject: [PATCH 1/2] Fix typeerror with bytes docstrings --- src/pydocstyle/checker.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/pydocstyle/checker.py b/src/pydocstyle/checker.py index 0b45644..8b3b2c5 100644 --- a/src/pydocstyle/checker.py +++ b/src/pydocstyle/checker.py @@ -246,7 +246,12 @@ def check_one_liners(self, definition, docstring): """ if docstring: - lines = ast.literal_eval(docstring).split('\n') + docstring_text = ast.literal_eval(docstring) + if isinstance(docstring_text, bytes): + docstring_text = docstring_text.decode() + + lines = docstring_text.split('\n') + if len(lines) > 1: non_empty_lines = sum(1 for l in lines if not is_blank(l)) if non_empty_lines == 1: From 814bd2707ff0f13bd48ef15a72b2c64f3d3478f3 Mon Sep 17 00:00:00 2001 From: Tushar Sadhwani <86737547+tushar-deepsource@users.noreply.github.com> Date: Fri, 10 Feb 2023 15:05:43 +0530 Subject: [PATCH 2/2] Don't check byte docstrings. --- src/pydocstyle/checker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pydocstyle/checker.py b/src/pydocstyle/checker.py index 8b3b2c5..8c1a080 100644 --- a/src/pydocstyle/checker.py +++ b/src/pydocstyle/checker.py @@ -248,7 +248,8 @@ def check_one_liners(self, definition, docstring): if docstring: docstring_text = ast.literal_eval(docstring) if isinstance(docstring_text, bytes): - docstring_text = docstring_text.decode() + # bytes objects are not valid docstrings. + return lines = docstring_text.split('\n')