lapsed 2.4.2__tar.gz → 2.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. {lapsed-2.4.2 → lapsed-2.5.0}/PKG-INFO +7 -2
  2. {lapsed-2.4.2 → lapsed-2.5.0}/README.md +6 -1
  3. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/parse_arguments.py +12 -0
  4. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/data_types.py +1 -0
  5. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/dead_code_visitor.py +3 -0
  6. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/ignore.py +6 -0
  7. {lapsed-2.4.2 → lapsed-2.5.0}/pyproject.toml +1 -1
  8. {lapsed-2.4.2 → lapsed-2.5.0}/.gitignore +0 -0
  9. {lapsed-2.4.2 → lapsed-2.5.0}/LICENSE +0 -0
  10. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/__init__.py +0 -0
  11. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/__init__.py +0 -0
  12. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/find_python_filenames.py +0 -0
  13. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/find_unused_names.py +0 -0
  14. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/fix_or_show_unused_code.py +0 -0
  15. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/get_unused_names_error_message.py +0 -0
  16. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/merge_overlaping_file_parts.py +0 -0
  17. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/parse_abstract_syntax_tree.py +0 -0
  18. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/parse_tach_config.py +0 -0
  19. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/actions/remove_file_parts_from_content.py +0 -0
  20. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/cli.py +0 -0
  21. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/constants.py +0 -0
  22. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/__init__.py +0 -0
  23. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/add_colors_to_diff.py +0 -0
  24. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/base_test_case.py +0 -0
  25. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/fix_indent.py +0 -0
  26. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/flatten_lists.py +0 -0
  27. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/nested_scopes.py +0 -0
  28. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/utils/print_ast.py +0 -0
  29. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/__init__.py +0 -0
  30. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/code_item.py +0 -0
  31. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/lines.py +0 -0
  32. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/noqa.py +0 -0
  33. {lapsed-2.4.2 → lapsed-2.5.0}/deadcode/visitor/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lapsed
3
- Version: 2.4.2
3
+ Version: 2.5.0
4
4
  Summary: Find and remove dead code.
5
5
  Project-URL: homepage, https://github.com/albertas/deadcode
6
6
  Project-URL: documentation, https://deadcode.readthedocs.io/
@@ -94,7 +94,7 @@ Create a `.pre-commit-config.yaml` file in the root of your project directory, i
94
94
  # See https://pre-commit.com/hooks.html for more hooks
95
95
  repos:
96
96
  - repo: https://github.com/albertas/deadcode
97
- rev: 2.4.2
97
+ rev: 2.5.0
98
98
  hooks:
99
99
  - id: deadcode
100
100
  ```
@@ -117,6 +117,7 @@ repos:
117
117
  |`--ignore-definitions` | list | Ignores definition (including name and body) if a name of an expression matches any of the provided ones. |
118
118
  |`--ignore-definitions-if-inherits-from` | list | Ignores definition (including name and body) of a class if it inherits from any of the provided class names. |
119
119
  |`--ignore-definitions-if-decorated-with` | list | Ignores definition (including name and body) of an expression, which is decorated with any of the provided decorator names. |
120
+ |`--ignore-non-self-attributes` | - | Does not report unused attributes assigned on objects other than `self`, e.g. `foo.bar = 1`. Such assignments may have side effects or be consumed by code outside of the analysed files, so they cannot safely be assumed dead. |
120
121
  |`--tach-config` | list | Paths to `tach.toml` files (see [Tach](https://docs.gauge.sh)). Names exposed via `[[interfaces]]` are treated as public API and never reported as unused; files in `unchecked = true` modules are skipped entirely. |
121
122
  |`--no-color` | - | Removes colors from the output. |
122
123
  |`--count` | - | Provides the count of the detected unused names instead of printing them all out. |
@@ -225,6 +226,10 @@ code base is implemented in.
225
226
  - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
226
227
 
227
228
  ## Release notes
229
+ - v2.5.0:
230
+ - Add `--ignore-non-self-attributes` option to not report unused attributes assigned on
231
+ objects other than `self` (e.g. `foo.bar = 1`), since such assignments may have side
232
+ effects or be consumed by code outside of the analysed files.
228
233
  - v2.4.2:
229
234
  - Add `--tach-config` option to read `tach.toml` file(s) and treat names exposed via `[[interfaces]]`
230
235
  as public API, and skip `unchecked = true` modules entirely.
@@ -66,7 +66,7 @@ Create a `.pre-commit-config.yaml` file in the root of your project directory, i
66
66
  # See https://pre-commit.com/hooks.html for more hooks
67
67
  repos:
68
68
  - repo: https://github.com/albertas/deadcode
69
- rev: 2.4.2
69
+ rev: 2.5.0
70
70
  hooks:
71
71
  - id: deadcode
72
72
  ```
@@ -89,6 +89,7 @@ repos:
89
89
  |`--ignore-definitions` | list | Ignores definition (including name and body) if a name of an expression matches any of the provided ones. |
90
90
  |`--ignore-definitions-if-inherits-from` | list | Ignores definition (including name and body) of a class if it inherits from any of the provided class names. |
91
91
  |`--ignore-definitions-if-decorated-with` | list | Ignores definition (including name and body) of an expression, which is decorated with any of the provided decorator names. |
92
+ |`--ignore-non-self-attributes` | - | Does not report unused attributes assigned on objects other than `self`, e.g. `foo.bar = 1`. Such assignments may have side effects or be consumed by code outside of the analysed files, so they cannot safely be assumed dead. |
92
93
  |`--tach-config` | list | Paths to `tach.toml` files (see [Tach](https://docs.gauge.sh)). Names exposed via `[[interfaces]]` are treated as public API and never reported as unused; files in `unchecked = true` modules are skipped entirely. |
93
94
  |`--no-color` | - | Removes colors from the output. |
94
95
  |`--count` | - | Provides the count of the detected unused names instead of printing them all out. |
@@ -197,6 +198,10 @@ code base is implemented in.
197
198
  - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
198
199
 
199
200
  ## Release notes
201
+ - v2.5.0:
202
+ - Add `--ignore-non-self-attributes` option to not report unused attributes assigned on
203
+ objects other than `self` (e.g. `foo.bar = 1`), since such assignments may have side
204
+ effects or be consumed by code outside of the analysed files.
200
205
  - v2.4.2:
201
206
  - Add `--tach-config` option to read `tach.toml` file(s) and treat names exposed via `[[interfaces]]`
202
207
  as public API, and skip `unchecked = true` modules entirely.
@@ -167,6 +167,18 @@ def parse_arguments(args: Optional[List[str]]) -> Args:
167
167
  type=str,
168
168
  )
169
169
 
170
+ parser.add_argument(
171
+ '--ignore-non-self-attributes',
172
+ help=(
173
+ 'Does not report unused attributes assigned on objects other than `self`, e.g. `foo.bar = 1` '
174
+ 'where `foo` is not the first argument of the enclosing method. Such assignments may have '
175
+ 'side effects or be consumed by code outside of the analysed files, so they cannot safely '
176
+ 'be assumed dead.'
177
+ ),
178
+ action='store_true',
179
+ default=False,
180
+ )
181
+
170
182
  parser.add_argument(
171
183
  '--tach-config',
172
184
  help=(
@@ -31,6 +31,7 @@ class Args:
31
31
  ignore_names_if_decorated_with: Iterable[Pathname] = ()
32
32
  ignore_names_if_inherits_from: Iterable[Pathname] = ()
33
33
  ignore_names_in_files: Iterable[Pathname] = ()
34
+ ignore_non_self_attributes: bool = False
34
35
  tach_config: Iterable[Pathname] = ()
35
36
  no_color: bool = False
36
37
  quiet: bool = False
@@ -35,6 +35,7 @@ from deadcode.visitor.ignore import (
35
35
  _ignore_method,
36
36
  _ignore_pytest_fixture,
37
37
  _ignore_variable,
38
+ _is_self_attribute,
38
39
  )
39
40
 
40
41
  logger = getLogger()
@@ -301,6 +302,8 @@ class DeadCodeVisitor(ast.NodeVisitor):
301
302
 
302
303
  def visit_Attribute(self, node: ast.Attribute) -> None:
303
304
  if isinstance(node.ctx, ast.Store):
305
+ if self.args.ignore_non_self_attributes and not _is_self_attribute(node):
306
+ return
304
307
  self._define(self.defined_attrs, node.attr, node)
305
308
  elif isinstance(node.ctx, ast.Load):
306
309
  self.add_used_name(node.attr)
@@ -123,6 +123,12 @@ def _ignore_method(filename: Path, method_name: str) -> bool:
123
123
  )
124
124
 
125
125
 
126
+ def _is_self_attribute(node: ast.Attribute) -> bool:
127
+ """Whether an attribute assignment target is `self.attr` (as opposed to
128
+ e.g. `foo.attr`, where `foo` is some other object)."""
129
+ return isinstance(node.value, ast.Name) and node.value.id == 'self'
130
+
131
+
126
132
  def _ignore_variable(filename: Path, varname: str) -> bool:
127
133
  """
128
134
  Ignore _ (Python idiom), _x (pylint convention) and
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lapsed"
3
- version = "2.4.2"
3
+ version = "2.5.0"
4
4
  authors = [
5
5
  {name = "Albertas Gimbutas", email = "albertasgim@gmail.com"},
6
6
  ]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes