Skip to content

Fix all flake8 issues #4535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 4, 2021
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
1 change: 0 additions & 1 deletion .circleci/unittest/linux/scripts/run-clang-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"""

import argparse
import codecs
import difflib
import fnmatch
import io
Expand Down
1 change: 0 additions & 1 deletion packaging/wheel/relocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Third party imports
if sys.platform == "linux":
from auditwheel.lddtree import lddtree
from wheel.bdist_wheel import get_abi_tag


ALLOWLIST = {
Expand Down
4 changes: 3 additions & 1 deletion references/classification/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class ExponentialMovingAverage(torch.optim.swa_utils.AveragedModel):
"""

def __init__(self, model, decay, device="cpu"):
ema_avg = lambda avg_model_param, model_param, num_averaged: decay * avg_model_param + (1 - decay) * model_param
def ema_avg(avg_model_param, model_param, num_averaged):
return decay * avg_model_param + (1 - decay) * model_param

super().__init__(model, device, ema_avg)

def update_parameters(self, model):
Expand Down
1 change: 0 additions & 1 deletion references/detection/coco_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import torch.utils.data
import torchvision
import transforms as T
from PIL import Image
from pycocotools import mask as coco_mask
from pycocotools.coco import COCO

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ license_file = LICENSE
max-line-length = 120

[flake8]
# note: we ignore all 501s (line too long) anyway as they're taken care of by black
max-line-length = 120
ignore = E203, E402, W503, W504, F821
ignore = E203, E402, W503, W504, F821, E501
per-file-ignores =
__init__.py: F401, F403, F405
./hubconf.py: F401
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import glob
import io
import os
import re
import shutil
import subprocess
import sys
from distutils.version import StrictVersion

import torch
from pkg_resources import parse_version, get_distribution, DistributionNotFound
Expand Down
10 changes: 1 addition & 9 deletions test/common_utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import argparse
import contextlib
import functools
import inspect
import os
import random
import shutil
import sys
import tempfile
import unittest
from collections import OrderedDict
from numbers import Number

import numpy as np
import pytest
import torch
from PIL import Image
from torch._six import string_classes
from torchvision import io

import __main__
import __main__ # noqa: 401


IN_CIRCLE_CI = os.getenv("CIRCLECI", False) == "true"
Expand Down
2 changes: 0 additions & 2 deletions test/test_backbone_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import random
from functools import partial
from itertools import chain

import pytest
import torch
import torchvision
from common_utils import set_rng_seed
from torchvision import models
from torchvision.models._utils import IntermediateLayerGetter
Expand Down
2 changes: 1 addition & 1 deletion test/test_cpp_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import torch
import torchvision.transforms.functional as F
from PIL import Image
from torchvision import models, transforms
from torchvision import models

try:
from torchvision import _C_tests
Expand Down
7 changes: 1 addition & 6 deletions test/test_datasets_samplers.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import contextlib
import os
import sys

import pytest
import torch
from common_utils import get_list_of_videos, assert_equal
from torchvision import get_video_backend
from torchvision import io
from torchvision.datasets.samplers import (
DistributedSampler,
RandomClipSampler,
UniformClipSampler,
)
from torchvision.datasets.video_utils import VideoClips, unfold
from torchvision.datasets.video_utils import VideoClips


@pytest.mark.skipif(not io.video._av_available(), reason="this test requires av")
Expand Down
5 changes: 0 additions & 5 deletions test/test_datasets_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import bz2
import contextlib
import gzip
import itertools
import lzma
import os
import tarfile
import warnings
import zipfile
from urllib.error import URLError

import pytest
import torchvision.datasets.utils as utils
Expand Down
3 changes: 0 additions & 3 deletions test/test_datasets_video_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import contextlib
import os

import pytest
import torch
from common_utils import get_list_of_videos, assert_equal
Expand Down
2 changes: 1 addition & 1 deletion test/test_datasets_video_utils_opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

import test_datasets_video_utils
from torchvision import set_video_backend
from torchvision import set_video_backend # noqa: 401

# Disabling the video backend switching temporarily
# set_video_backend('video_reader')
Expand Down
3 changes: 1 addition & 2 deletions test/test_functional_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import itertools
import math
import os
from functools import partial
from typing import Dict, List, Sequence, Tuple
from typing import Sequence

import numpy as np
import pytest
Expand Down
1 change: 0 additions & 1 deletion test/test_internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import os
import warnings
from urllib.error import URLError

import pytest
Expand Down
2 changes: 0 additions & 2 deletions test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
import sys
import tempfile
import warnings
from urllib.error import URLError

import pytest
import torch
Expand Down
2 changes: 1 addition & 1 deletion test/test_io_opt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

import test_io
from torchvision import set_video_backend
from torchvision import set_video_backend # noqa: 401


# Disabling the video backend switching temporarily
Expand Down
1 change: 0 additions & 1 deletion test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import io
import operator
import os
import sys
import traceback
import warnings
from collections import OrderedDict
Expand Down
1 change: 0 additions & 1 deletion test/test_transforms_tensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
from typing import Sequence

import numpy as np
import pytest
Expand Down
4 changes: 2 additions & 2 deletions torchvision/_internally_replaced_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ def _is_remote_location_available() -> bool:


try:
from torch.hub import load_state_dict_from_url
from torch.hub import load_state_dict_from_url # noqa: 401
except ImportError:
from torch.utils.model_zoo import load_url as load_state_dict_from_url
from torch.utils.model_zoo import load_url as load_state_dict_from_url # noqa: 401


def _get_extension_path(lib_name):
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Any, Callable, Optional, Tuple

import numpy as np
import torch
from PIL import Image

from .utils import check_integrity, download_and_extract_archive
Expand Down
1 change: 0 additions & 1 deletion torchvision/datasets/widerface.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from PIL import Image

from .utils import (
check_integrity,
download_file_from_google_drive,
download_and_extract_archive,
extract_archive,
Expand Down
1 change: 0 additions & 1 deletion torchvision/io/_video_opt.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
import os
import warnings
from fractions import Fraction
from typing import List, Tuple
Expand Down
4 changes: 2 additions & 2 deletions torchvision/models/densenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ def closure(*inputs):
return cp.checkpoint(closure, *input)

@torch.jit._overload_method # noqa: F811
def forward(self, input: List[Tensor]) -> Tensor:
def forward(self, input: List[Tensor]) -> Tensor: # noqa: F811
pass

@torch.jit._overload_method # noqa: F811
def forward(self, input: Tensor) -> Tensor:
def forward(self, input: Tensor) -> Tensor: # noqa: F811
pass

# torchscript does not yet support *args, so we overload method
Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/rpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import _utils as det_utils

# Import AnchorGenerator to keep compatibility.
from .anchor_utils import AnchorGenerator
from .anchor_utils import AnchorGenerator # noqa: 401
from .image_list import ImageList


Expand Down
2 changes: 1 addition & 1 deletion torchvision/models/detection/ssdlite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import warnings
from collections import OrderedDict
from functools import partial
from typing import Any, Callable, Dict, List, Optional, Tuple
from typing import Any, Callable, Dict, List, Optional

import torch
from torch import nn, Tensor
Expand Down
1 change: 0 additions & 1 deletion torchvision/models/mobilenetv2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import warnings
from functools import partial
from typing import Callable, Any, Optional, List

import torch
Expand Down
7 changes: 1 addition & 6 deletions torchvision/ops/_register_onnx_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@


def _register_custom_op():
from torch.onnx.symbolic_helper import (
parse_args,
scalar_type_to_onnx,
scalar_type_to_pytorch_type,
cast_pytorch_to_onnx,
)
from torch.onnx.symbolic_helper import parse_args
from torch.onnx.symbolic_opset11 import select, squeeze, unsqueeze
from torch.onnx.symbolic_opset9 import _cast_Long

Expand Down