lapsed 2.6.0__tar.gz → 2.7.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.6.0 → lapsed-2.7.0}/PKG-INFO +8 -2
  2. {lapsed-2.6.0 → lapsed-2.7.0}/README.md +7 -1
  3. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/dead_code_visitor.py +3 -0
  4. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/ignore.py +28 -1
  5. {lapsed-2.6.0 → lapsed-2.7.0}/pyproject.toml +1 -1
  6. {lapsed-2.6.0 → lapsed-2.7.0}/.gitignore +0 -0
  7. {lapsed-2.6.0 → lapsed-2.7.0}/LICENSE +0 -0
  8. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/__init__.py +0 -0
  9. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/__init__.py +0 -0
  10. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/find_python_filenames.py +0 -0
  11. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/find_unused_names.py +0 -0
  12. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/fix_or_show_unused_code.py +0 -0
  13. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/get_unused_names_error_message.py +0 -0
  14. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/merge_overlaping_file_parts.py +0 -0
  15. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/parse_abstract_syntax_tree.py +0 -0
  16. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/parse_arguments.py +0 -0
  17. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/parse_tach_config.py +0 -0
  18. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/actions/remove_file_parts_from_content.py +0 -0
  19. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/cli.py +0 -0
  20. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/constants.py +0 -0
  21. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/data_types.py +0 -0
  22. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/__init__.py +0 -0
  23. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/add_colors_to_diff.py +0 -0
  24. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/base_test_case.py +0 -0
  25. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/fix_indent.py +0 -0
  26. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/flatten_lists.py +0 -0
  27. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/nested_scopes.py +0 -0
  28. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/utils/print_ast.py +0 -0
  29. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/__init__.py +0 -0
  30. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/code_item.py +0 -0
  31. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/lines.py +0 -0
  32. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/noqa.py +0 -0
  33. {lapsed-2.6.0 → lapsed-2.7.0}/deadcode/visitor/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: lapsed
3
- Version: 2.6.0
3
+ Version: 2.7.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.6.0
97
+ rev: 2.7.0
98
98
  hooks:
99
99
  - id: deadcode
100
100
  ```
@@ -227,6 +227,12 @@ code base is implemented in.
227
227
  - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
228
228
 
229
229
  ## Release notes
230
+ - v2.7.0:
231
+ - Treat `pytest_*` functions defined in `conftest.py` (e.g. `pytest_configure`,
232
+ `pytest_collection_modifyitems`, `pytest_addoption`) as pytest hooks, which pytest
233
+ calls automatically by name, and never report them as unused.
234
+ - Treat methods decorated with `@typing.override` (or `@typing_extensions.override`)
235
+ as used, since they are called via the base class they override, not by their own name.
230
236
  - v2.6.0:
231
237
  - Add `--ignore-class-attributes` option to not report unused attributes assigned directly
232
238
  in a class body (e.g. `THING = "blah"` inside `class Foo:`), since such attributes may
@@ -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.6.0
69
+ rev: 2.7.0
70
70
  hooks:
71
71
  - id: deadcode
72
72
  ```
@@ -199,6 +199,12 @@ code base is implemented in.
199
199
  - [ ] Investigate ways of extracting and backporting Python3.10+ `ast` implementation to lower Python versions.
200
200
 
201
201
  ## Release notes
202
+ - v2.7.0:
203
+ - Treat `pytest_*` functions defined in `conftest.py` (e.g. `pytest_configure`,
204
+ `pytest_collection_modifyitems`, `pytest_addoption`) as pytest hooks, which pytest
205
+ calls automatically by name, and never report them as unused.
206
+ - Treat methods decorated with `@typing.override` (or `@typing_extensions.override`)
207
+ as used, since they are called via the base class they override, not by their own name.
202
208
  - v2.6.0:
203
209
  - Add `--ignore-class-attributes` option to not report unused attributes assigned directly
204
210
  in a class body (e.g. `THING = "blah"` inside `class Foo:`), since such attributes may
@@ -33,6 +33,7 @@ from deadcode.visitor.ignore import (
33
33
  _ignore_import,
34
34
  _ignore_function,
35
35
  _ignore_method,
36
+ _ignore_override,
36
37
  _ignore_pytest_fixture,
37
38
  _ignore_variable,
38
39
  _is_self_attribute,
@@ -442,6 +443,8 @@ class DeadCodeVisitor(ast.NodeVisitor):
442
443
  self._log(f'Ignoring {type_} "{node.name}" (decorator whitelisted)')
443
444
  elif _ignore_pytest_fixture(self.filename, decorator_names):
444
445
  self._log(f'Ignoring {type_} "{node.name}" (pytest fixture)')
446
+ elif _ignore_override(decorator_names):
447
+ self._log(f'Ignoring {type_} "{node.name}" (typing.override)')
445
448
  elif type_ == 'property':
446
449
  self._define(self.defined_props, node.name, node)
447
450
  elif type_ == 'method':
@@ -29,6 +29,11 @@ PYTEST_USEFIXTURES_DECORATOR_NAMES = {
29
29
  '@mark.usefixtures',
30
30
  '@usefixtures',
31
31
  }
32
+ OVERRIDE_DECORATOR_NAMES = {
33
+ '@typing.override',
34
+ '@typing_extensions.override',
35
+ '@override',
36
+ }
32
37
 
33
38
  ERROR_CODES = {
34
39
  'variable': b'DC01',
@@ -98,7 +103,19 @@ def _ignore_import(filename: Path, import_name: str) -> bool:
98
103
 
99
104
 
100
105
  def _ignore_function(filename: Path, function_name: str) -> bool:
101
- return (function_name in PYTEST_FUNCTION_NAMES or function_name.startswith('test_')) and _is_test_file(filename)
106
+ return (
107
+ (function_name in PYTEST_FUNCTION_NAMES or function_name.startswith('test_')) and _is_test_file(filename)
108
+ ) or _ignore_pytest_hook(filename, function_name)
109
+
110
+
111
+ def _ignore_pytest_hook(filename: Path, function_name: str) -> bool:
112
+ """
113
+ `pytest_*` functions in conftest.py (e.g. `pytest_configure`,
114
+ `pytest_collection_modifyitems`, `pytest_addoption`) are hook
115
+ implementations that pytest calls automatically by name, never directly,
116
+ so they would otherwise look unused.
117
+ """
118
+ return _is_conftest_file(filename) and function_name.startswith('pytest_')
102
119
 
103
120
 
104
121
  def _ignore_pytest_fixture(filename: Path, decorator_names: Iterable[str]) -> bool:
@@ -117,6 +134,16 @@ def _ignore_pytest_fixture(filename: Path, decorator_names: Iterable[str]) -> bo
117
134
  )
118
135
 
119
136
 
137
+ def _ignore_override(decorator_names: Iterable[str]) -> bool:
138
+ """
139
+ `@typing.override` (and `@typing_extensions.override`) marks a method as
140
+ overriding one declared on a base class. The base class's method is what
141
+ calling code actually calls, so this override is used even though nothing
142
+ calls it by its own name directly.
143
+ """
144
+ return _match_many(decorator_names, OVERRIDE_DECORATOR_NAMES)
145
+
146
+
120
147
  def _ignore_method(filename: Path, method_name: str) -> bool:
121
148
  return _is_special_name(method_name) or (
122
149
  (method_name in PYTEST_METHOD_NAMES or method_name.startswith('test_')) and _is_test_file(filename)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "lapsed"
3
- version = "2.6.0"
3
+ version = "2.7.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
File without changes