From 86046fd8bd55cb6d356b1f1ce3dc10a299225826 Mon Sep 17 00:00:00 2001 From: "dor.abu" Date: Tue, 6 Jul 2021 10:30:33 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A1=20PR=20comments=20resolution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- codemate/block.py | 16 +++++----------- codemate/utils.py | 2 +- tests/block/test_add_import.py | 2 +- tests/utils.py | 2 +- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/codemate/block.py b/codemate/block.py index a5cddc5..a93bada 100644 --- a/codemate/block.py +++ b/codemate/block.py @@ -117,7 +117,7 @@ def add_doc_lines(self, *lines: str, indent: int = 0) -> "Block": Block: The block instance. """ add_doc_line = partial(self.add_doc_line, indent=indent) - tuple(map(add_doc_line, lines)) + list(map(add_doc_line, lines)) return self def add_doc_block(self, block: str, indent: int = 0) -> "Block": @@ -150,22 +150,16 @@ def add_import(self, module: str) -> "Block": def add_imports(self, *modules: str) -> "Block": """ - Adds imports syntax lines to the Python block syntax. + Adds imports syntax lines to the Python block syntax, + Ignores empty modules names. Args: modules (Collection[str]): The modules names that we want to import. Returns: Block: The block instance. - - Raises: - ValueError: When one of the provided modules is an empty string. """ - for module in modules: - if module: - self.add_import(module) - else: - raise ValueError("Module name can't be empty") + list(map(self.add_import, filter(bool, modules))) return self def add_specific_import(self, module: str, *components: str) -> "Block": @@ -357,7 +351,7 @@ def validate(self) -> bool: else: return True - def __repr__(self): + def __repr__(self) -> str: class_name = getattr(type(self), "__name__", type(self)) return f"{class_name}({vars(self)})" diff --git a/codemate/utils.py b/codemate/utils.py index 930de1b..0b20382 100644 --- a/codemate/utils.py +++ b/codemate/utils.py @@ -12,6 +12,6 @@ def remove_indentation(content: str) -> str: Returns: str: The unindented content. """ - indentation = next(iter(re.findall("^\n*( *)", content) or []), "") + indentation = next(iter(re.findall("^\n*( *)", content)), "") unindented = re.subn(f"(\n){indentation}", r"\1", content)[0].strip() return unindented diff --git a/tests/block/test_add_import.py b/tests/block/test_add_import.py index 3e14917..976ca6f 100644 --- a/tests/block/test_add_import.py +++ b/tests/block/test_add_import.py @@ -7,7 +7,7 @@ SINGLE_IMPORT_RESULT: str = isort.code("import math") -MULTIPLE_IMPORTS = ("math", "sys", "math", "datetime") +MULTIPLE_IMPORTS = ("math", "sys", "math", None, "datetime") MULTIPLE_IMPORTS_RESULT: str = isort.code( """ diff --git a/tests/utils.py b/tests/utils.py index 70cec91..25834e0 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -14,7 +14,7 @@ def get_syntax(use_black: bool = False, prefix: str = "", postfix: str = "") -> Returns: str: The formatted syntax. """ - syntax = prefix + postfix + syntax = f"{prefix}{postfix}" if use_black: return black.format_str(syntax, mode=black.FileMode()) return syntax