Skip to content

Commit

Permalink
💡 PR comments resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
dor-abu committed Jul 6, 2021
1 parent 3c15359 commit 86046fd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
16 changes: 5 additions & 11 deletions codemate/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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":
Expand Down Expand Up @@ -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)})"

Expand Down
2 changes: 1 addition & 1 deletion codemate/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/block/test_add_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 86046fd

Please sign in to comment.