flake8 and mypy errors
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 17.9k
- Forks
- 7.3k
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 13
Description
🐛 Describe the bug
I'm planning to contribute type annotations to the library as discussed and tracked in https://github.com/pytorch/vision/issues/2025. However, I encountered multiple flake8 and mypy errors on main as of 2cd25c1a05012a3720a87f20cec436811fadeedd. I'd like to fix these before adding additional type annotations. If the proposed fixes below look good I can make a PR.
Running
mypy --config-file mypy.ini yields
torchvision/prototype/datapoints/_datapoint.py:8: error: Module "torch._C" has no attribute "DisableTorchFunctionSubclass" [attr-defined]
from torch._C import DisableTorchFunctionSubclass
^
torchvision/prototype/transforms/_augment.py:137: error: Unused "type: ignore" comment
return dict(lam=float(self._dist.sample(()))) # type: ignore[arg-type]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
torchvision/prototype/transforms/_augment.py:159: error: Unused "type: ignore" comment
lam = float(self._dist.sample(())) # type: ignore[arg-type]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 3 errors in 2 files (checked 227 source files)
To address these I would
- Remove the two extra type ignores
- Add
# type: ignore[attr-defined]afterfrom torch._C import DisableTorchFunctionSubclass
Running flake8 yields
./test/test_ops.py:6:1: F401 'typing.Tuple' imported but unused
./torchvision/models/detection/generalized_rcnn.py:7:1: F401 'typing.Dict' imported but unused
./torchvision/models/detection/generalized_rcnn.py:7:1: F401 'typing.Optional' imported but unused
./torchvision/models/detection/generalized_rcnn.py:7:1: F401 'typing.Union' imported but unused
./torchvision/models/detection/generalized_rcnn.py:10:1: F401 'torch.Tensor' imported but unused
./torchvision/models/detection/roi_heads.py:1:1: F401 'typing.Optional' imported but unused
./torchvision/models/detection/roi_heads.py:1:1: F401 'typing.Tuple' imported but unused
./torchvision/models/detection/roi_heads.py:6:1: F401 'torch.Tensor' imported but unused
To address these I would
- Remove the unused type imports. They only seemingly get used in docstring type hints. However, removing the import fixes the flake8 errors and doesn't cause issues with ufmt in my testing. example of current docstring type hint that likely led to these imports being added
# type: (Dict[str, Tensor], List[Dict[str, Tensor]]) -> Union[Dict[str, Tensor], List[Dict[str, Tensor]]]
Versions
Collecting environment information...
PyTorch version: 1.13.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 13.1 (x86_64)
GCC version: Could not collect
Clang version: 14.0.0 (clang-1400.0.29.202)
CMake version: Could not collect
Libc version: N/A
Python version: 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:42:20) [Clang 14.0.6 ] (64-bit runtime)
Python platform: macOS-13.1-x86_64-i386-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
CPU:
Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Versions of relevant libraries:
[pip3] mypy==1.0.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.2
[pip3] torch==1.13.1
[pip3] torchvision==0.15.0a0+378a327
[conda] mkl 2022.2.1 h44ed08c_16952 conda-forge
[conda] numpy 1.24.2 py39h6ee2318_0 conda-forge
[conda] pytorch 1.13.1 cpu_py39he8d27a1_1 conda-forge
[conda] torchvision 0.15.0a0+378a327 dev_0 <develop>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run mypy --config-file mypy.ini and flake8 at the referenced revision. Inspect the reported lines in torchvision/prototype/datapoints/_datapoint.py, torchvision/prototype/transforms/_augment.py, test/test_ops.py, and the listed detection files. Done means the reported mypy and flake8 errors are resolved without introducing test or formatting issues.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100