Skip to content

Commit

Permalink
Remove expression_code_parts from CodeItem
Browse files Browse the repository at this point in the history
since newly chosen implementation strategy no longer depend on it.
The invalid code adjustments will be implemented during AST visiting step
instead of writing to file step.
  • Loading branch information
albertas committed Jun 24, 2024
1 parent 5fdd707 commit fc5b6d7
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 36 deletions.
2 changes: 1 addition & 1 deletion deadcode/actions/remove_file_parts_from_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def remove_file_parts_from_content(content_lines: List[str], unused_file_parts:

# Remove trailing comma, if we have removed something.
# TODO: this should be applied only for specific expression types only.
if line.lstrip().startswith(","):
if line.lstrip().startswith(','):
line = line.lstrip()[1:].lstrip()

unused_part_index += 1
Expand Down
20 changes: 0 additions & 20 deletions deadcode/visitor/code_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class CodeItem: # TODO: This should also be a dataclass, because hash and tuple
'type_',
'filename',
'code_parts',
'expression_code_parts',
'scope',
'inherits_from',
'name_line',
Expand All @@ -61,13 +60,7 @@ def __init__(
name: str,
type_: UnusedCodeType,
filename: Path,
# These arguments are being converted to Part
# first_lineno: int = 0,
# last_lineno: int = 0,
# first_column: int = 0,
# last_column: Optional[int] = None,
code_parts: Optional[List[Part]] = None, # TODO: I should use a dataclass instead of a tuple for Part.
expression_code_parts: Optional[List[Part]] = None,
scope: Optional[str] = None,
inherits_from: Optional[List[str]] = None,
name_line: Optional[int] = None,
Expand All @@ -87,19 +80,6 @@ def __init__(
else:
self.code_parts = code_parts

if expression_code_parts is None:
self.expression_code_parts = []
else:
self.expression_code_parts = expression_code_parts

# if first_lineno is not None:
# pass

# self.first_lineno = first_lineno
# self.last_lineno = last_lineno
# self.first_column = first_column
# self.last_column = last_column

self.error_code = ERROR_TYPE_TO_ERROR_CODE[type_]
self.message = message

Expand Down
15 changes: 0 additions & 15 deletions deadcode/visitor/dead_code_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def _add_aliases(self, node: Union[ast.Import, ast.ImportFrom]) -> None:
self.defined_imports,
alias or name,
first_node=name_and_alias,
expression_node=node,
ignore=_ignore_import,
)
if alias is not None:
Expand Down Expand Up @@ -235,7 +234,6 @@ def _define(
name: str,
first_node: ast.AST,
last_node: Optional[ast.AST] = None,
expression_node: Optional[ast.AST] = None,
message: str = '',
ignore: Optional[Callable[[Path, str], bool]] = None,
) -> None:
Expand Down Expand Up @@ -274,19 +272,6 @@ def ignored(lineno: int, type_: UnusedCodeType) -> bool:
inherits_from=inherits_from,
)

# TODO: Remaining import expressions has to be removed, when all imported
# names get removed. Pass whole import expression parts and evaluate if its still
# empty after making code adjustments.
# This feature is not yet implemented.
if expression_node:
expression_first_lineno = lines.get_first_line_number(expression_node)
expression_last_lineno = lines.get_last_line_number(expression_node)
code_item.expression_code_parts = [Part(
expression_first_lineno,
expression_last_lineno,
expression_node.col_offset,
expression_node.end_col_offset or 0)]

self.scopes.add(code_item)

if ignored(first_lineno, type_=type_):
Expand Down

0 comments on commit fc5b6d7

Please sign in to comment.