Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,23 @@ jobs:
- name: mypy check
run: |
mypy

dead-code-vulture:
name: Python dead code checker
runs-on: ubuntu-20.04

# Timeout: https://stackoverflow.com/a/59076067/4521646
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: 3.7

- name: Install dependencies
run: pip install vulture && pip list

- name: Check for dead code with Vulture
run: |
vulture pytorch_lightning
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,3 @@ cifar-10-batches-py
*.pt
# ctags
tags
data
MNIST
runs
*trace*
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ repos:
name: Format code
language: python

- repo: https://github.com/jendrikseipp/vulture
rev: 'v2.3'
hooks:
- id: vulture

- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,28 @@ profile = "black"
line_length = 120
force_sort_within_sections = "False"
order_by_type = "False"

[tool.vulture]
exclude = ['pytorch_lightning/metrics']
make_whitelist = true
min_confidence = 95
paths = ["pytorch_lightning"]
ignore_names = [
"*_nb",
"*batch",
"*idx",
"*param*",
"cmd_line",
"kw",
"loc",
"mocked_device_count*",
"my_path",
"new_device",
"new_dtype",
"prediction",
"root",
"signum",
"torch_save",
"using_lbfgs",
]
sort_by_size = true
2 changes: 1 addition & 1 deletion pytorch_lightning/profiler/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __enter__(self) -> None:

self._handles[module_name] = [pre_forward_handle, post_forward_handle]

def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None:
def __exit__(self, type: Any, value: Any, traceback: Any) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type is a built-in keyword.
better to avoid name clash here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vulture picks up exc_type because it doesn't match the parent signature. We have a few options:

  • leave like this, matches the parent
  • convert to _, __, ___ - standard for unused variables
  • add to whitelist (already a bit big)

for handles in self._handles.values():
for h in handles:
h.remove()
Expand Down