Skip to content

Commit fc5b6d7

Browse files
committed
Remove expression_code_parts from CodeItem
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.
1 parent 5fdd707 commit fc5b6d7

File tree

3 files changed

+1
-36
lines changed

3 files changed

+1
-36
lines changed

deadcode/actions/remove_file_parts_from_content.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def remove_file_parts_from_content(content_lines: List[str], unused_file_parts:
101101

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

107107
unused_part_index += 1

deadcode/visitor/code_item.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class CodeItem: # TODO: This should also be a dataclass, because hash and tuple
4646
'type_',
4747
'filename',
4848
'code_parts',
49-
'expression_code_parts',
5049
'scope',
5150
'inherits_from',
5251
'name_line',
@@ -61,13 +60,7 @@ def __init__(
6160
name: str,
6261
type_: UnusedCodeType,
6362
filename: Path,
64-
# These arguments are being converted to Part
65-
# first_lineno: int = 0,
66-
# last_lineno: int = 0,
67-
# first_column: int = 0,
68-
# last_column: Optional[int] = None,
6963
code_parts: Optional[List[Part]] = None, # TODO: I should use a dataclass instead of a tuple for Part.
70-
expression_code_parts: Optional[List[Part]] = None,
7164
scope: Optional[str] = None,
7265
inherits_from: Optional[List[str]] = None,
7366
name_line: Optional[int] = None,
@@ -87,19 +80,6 @@ def __init__(
8780
else:
8881
self.code_parts = code_parts
8982

90-
if expression_code_parts is None:
91-
self.expression_code_parts = []
92-
else:
93-
self.expression_code_parts = expression_code_parts
94-
95-
# if first_lineno is not None:
96-
# pass
97-
98-
# self.first_lineno = first_lineno
99-
# self.last_lineno = last_lineno
100-
# self.first_column = first_column
101-
# self.last_column = last_column
102-
10383
self.error_code = ERROR_TYPE_TO_ERROR_CODE[type_]
10484
self.message = message
10585

deadcode/visitor/dead_code_visitor.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ def _add_aliases(self, node: Union[ast.Import, ast.ImportFrom]) -> None:
188188
self.defined_imports,
189189
alias or name,
190190
first_node=name_and_alias,
191-
expression_node=node,
192191
ignore=_ignore_import,
193192
)
194193
if alias is not None:
@@ -235,7 +234,6 @@ def _define(
235234
name: str,
236235
first_node: ast.AST,
237236
last_node: Optional[ast.AST] = None,
238-
expression_node: Optional[ast.AST] = None,
239237
message: str = '',
240238
ignore: Optional[Callable[[Path, str], bool]] = None,
241239
) -> None:
@@ -274,19 +272,6 @@ def ignored(lineno: int, type_: UnusedCodeType) -> bool:
274272
inherits_from=inherits_from,
275273
)
276274

277-
# TODO: Remaining import expressions has to be removed, when all imported
278-
# names get removed. Pass whole import expression parts and evaluate if its still
279-
# empty after making code adjustments.
280-
# This feature is not yet implemented.
281-
if expression_node:
282-
expression_first_lineno = lines.get_first_line_number(expression_node)
283-
expression_last_lineno = lines.get_last_line_number(expression_node)
284-
code_item.expression_code_parts = [Part(
285-
expression_first_lineno,
286-
expression_last_lineno,
287-
expression_node.col_offset,
288-
expression_node.end_col_offset or 0)]
289-
290275
self.scopes.add(code_item)
291276

292277
if ignored(first_lineno, type_=type_):

0 commit comments

Comments
 (0)