The following issues were found

caffe2/quantization/server/elementwise_linear_dnnlowp_op_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 6 Column: 1

              import collections

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
from caffe2.python import core, dyndep, workspace
from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close
from hypothesis import given


            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 10 Column: 1

              import numpy as np
from caffe2.python import core, dyndep, workspace
from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close
from hypothesis import given


dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops")
workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"])


            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 27 Column: 67

                      **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0
        # All inputs have scale 1, so exactly represented after quantization
        min_ = -100

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              

import collections

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
from caffe2.python import core, dyndep, workspace
from caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close

            

Reported by Pylint.

Missing class docstring
Error

Line: 17 Column: 1

              workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"])


class DNNLowPElementwiseLinearOpTest(hu.HypothesisTestCase):
    @given(
        N=st.integers(32, 256),
        D=st.integers(32, 256),
        empty_batch=st.booleans(),
        in_quantized=st.booleans(),

            

Reported by Pylint.

Argument name "D" doesn't conform to snake_case naming style
Error

Line: 25 Column: 5

                      in_quantized=st.booleans(),
        out_quantized=st.booleans(),
        **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0

            

Reported by Pylint.

Argument name "N" doesn't conform to snake_case naming style
Error

Line: 25 Column: 5

                      in_quantized=st.booleans(),
        out_quantized=st.booleans(),
        **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0

            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 25 Column: 5

                      in_quantized=st.booleans(),
        out_quantized=st.booleans(),
        **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0

            

Reported by Pylint.

Too many local variables (24/15)
Error

Line: 25 Column: 5

                      in_quantized=st.booleans(),
        out_quantized=st.booleans(),
        **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0

            

Reported by Pylint.

Too many arguments (8/5)
Error

Line: 25 Column: 5

                      in_quantized=st.booleans(),
        out_quantized=st.booleans(),
        **hu.gcs_cpu_only
    )
    def test_dnnlowp_elementwise_linear_int(
        self, N, D, empty_batch, in_quantized, out_quantized, gc, dc
    ):
        if empty_batch:
            N = 0

            

Reported by Pylint.

caffe2/python/operator_test/merge_id_lists_op_test.py
16 issues
Unable to import 'hypothesis.extra.numpy'
Error

Line: 10 Column: 1

              import caffe2.python.hypothesis_test_util as hu
import caffe2.python.serialized_test.serialized_test_util as serial

import hypothesis.extra.numpy as hnp
import hypothesis.strategies as st
import numpy as np


@st.composite

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 11 Column: 1

              import caffe2.python.serialized_test.serialized_test_util as serial

import hypothesis.extra.numpy as hnp
import hypothesis.strategies as st
import numpy as np


@st.composite
def id_list_batch(draw):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import core
import caffe2.python.hypothesis_test_util as hu
import caffe2.python.serialized_test.serialized_test_util as serial


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

              

@st.composite
def id_list_batch(draw):
    num_inputs = draw(st.integers(1, 3))
    batch_size = draw(st.integers(5, 10))
    values_dtype = draw(st.sampled_from([np.int32, np.int64]))
    inputs = []
    for _ in range(num_inputs):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 1

                  return inputs


def merge_id_lists_ref(*args):
    n = len(args)
    assert n > 0
    assert n % 2 == 0
    batch_size = len(args[0])
    num_inputs = int(n / 2)

            

Reported by Pylint.

Variable name "n" doesn't conform to snake_case naming style
Error

Line: 33 Column: 5

              

def merge_id_lists_ref(*args):
    n = len(args)
    assert n > 0
    assert n % 2 == 0
    batch_size = len(args[0])
    num_inputs = int(n / 2)
    lengths = np.array([np.insert(args[2 * i], 0, 0)

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 34
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              
def merge_id_lists_ref(*args):
    n = len(args)
    assert n > 0
    assert n % 2 == 0
    batch_size = len(args[0])
    num_inputs = int(n / 2)
    lengths = np.array([np.insert(args[2 * i], 0, 0)
                        for i in range(num_inputs)])

            

Reported by Bandit.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 35
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

              def merge_id_lists_ref(*args):
    n = len(args)
    assert n > 0
    assert n % 2 == 0
    batch_size = len(args[0])
    num_inputs = int(n / 2)
    lengths = np.array([np.insert(args[2 * i], 0, 0)
                        for i in range(num_inputs)])
    values = [args[2 * i + 1] for i in range(num_inputs)]

            

Reported by Bandit.

Argument name "vs" doesn't conform to snake_case naming style
Error

Line: 43 Column: 5

                  values = [args[2 * i + 1] for i in range(num_inputs)]
    offsets = [np.cumsum(lengths[j]) for j in range(num_inputs)]

    def merge_arrays(vs, offs, j):
        concat = np.concatenate([vs[i][offs[i][j]:offs[i][j + 1]]
                                for i in range(num_inputs)])
        return np.sort(np.unique(concat))

    merged = [merge_arrays(values, offsets, j) for j in range(batch_size)]

            

Reported by Pylint.

Missing class docstring
Error

Line: 54 Column: 1

                  return merged_lengths, merged_values


class TestMergeIdListsOp(serial.SerializedTestCase):
    def test_merge_id_lists_ref(self):
        # Verify that the reference implementation is correct!
        lengths_0 = np.array([3, 0, 4], dtype=np.int32)
        values_0 = np.array([1, 5, 6, 2, 4, 5, 6], dtype=np.int64)
        lengths_1 = np.array([3, 2, 1], dtype=np.int32)

            

Reported by Pylint.

caffe2/python/operator_test/ensure_clipped_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 4 Column: 1

              

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 8 Column: 1

              import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


class TestEnsureClipped(hu.HypothesisTestCase):
    @given(
        X=hu.arrays(dims=[5, 10], elements=hu.floats(min_value=-1.0, max_value=1.0)),

            

Reported by Pylint.

Unused argument 'gc'
Error

Line: 19 Column: 65

                      indices=hu.arrays(dims=[5], elements=st.booleans()),
        **hu.gcs_cpu_only
    )
    def test_ensure_clipped(self, X, in_place, sparse, indices, gc, dc):
        if (not in_place) and sparse:
            return
        param = X.astype(np.float32)
        m, n = param.shape
        indices = np.array(np.nonzero(indices)[0], dtype=np.int64)

            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 19 Column: 69

                      indices=hu.arrays(dims=[5], elements=st.booleans()),
        **hu.gcs_cpu_only
    )
    def test_ensure_clipped(self, X, in_place, sparse, indices, gc, dc):
        if (not in_place) and sparse:
            return
        param = X.astype(np.float32)
        m, n = param.shape
        indices = np.array(np.nonzero(indices)[0], dtype=np.int64)

            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 29 Column: 9

                      workspace.FeedBlob("indices", indices)
        workspace.FeedBlob("grad", grad)
        workspace.FeedBlob("param", param)
        input = ["param", "indices", "grad"] if sparse else ["param"]
        output = "param" if in_place else "output"
        op = core.CreateOperator("EnsureClipped", input, output, min=0.0)
        workspace.RunOperatorOnce(op)

        def ref():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              from hypothesis import given


class TestEnsureClipped(hu.HypothesisTestCase):
    @given(
        X=hu.arrays(dims=[5, 10], elements=hu.floats(min_value=-1.0, max_value=1.0)),
        in_place=st.booleans(),
        sparse=st.booleans(),
        indices=hu.arrays(dims=[5], elements=st.booleans()),

            

Reported by Pylint.

Argument name "X" doesn't conform to snake_case naming style
Error

Line: 18 Column: 5

                      sparse=st.booleans(),
        indices=hu.arrays(dims=[5], elements=st.booleans()),
        **hu.gcs_cpu_only
    )
    def test_ensure_clipped(self, X, in_place, sparse, indices, gc, dc):
        if (not in_place) and sparse:
            return
        param = X.astype(np.float32)
        m, n = param.shape

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 5

                      sparse=st.booleans(),
        indices=hu.arrays(dims=[5], elements=st.booleans()),
        **hu.gcs_cpu_only
    )
    def test_ensure_clipped(self, X, in_place, sparse, indices, gc, dc):
        if (not in_place) and sparse:
            return
        param = X.astype(np.float32)
        m, n = param.shape

            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 18 Column: 5

                      sparse=st.booleans(),
        indices=hu.arrays(dims=[5], elements=st.booleans()),
        **hu.gcs_cpu_only
    )
    def test_ensure_clipped(self, X, in_place, sparse, indices, gc, dc):
        if (not in_place) and sparse:
            return
        param = X.astype(np.float32)
        m, n = param.shape

            

Reported by Pylint.

caffe2/quantization/server/batch_permutation_dnnlowp_op_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 4 Column: 1

              

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
from caffe2.python import core, dyndep, workspace
from hypothesis import given, settings



            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 7 Column: 1

              import hypothesis.strategies as st
import numpy as np
from caffe2.python import core, dyndep, workspace
from hypothesis import given, settings


dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops")
workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"])


            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 17 Column: 45

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

Unused argument 'gc'
Error

Line: 17 Column: 41

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
from caffe2.python import core, dyndep, workspace
from hypothesis import given, settings



            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"])


class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)

            

Reported by Pylint.

Method could be a function
Error

Line: 17 Column: 5

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 5

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              class DNNLowPBatchPermutationOpTest(hu.HypothesisTestCase):
    @given(N=st.integers(min_value=1, max_value=100), **hu.gcs_cpu_only)
    @settings(max_examples=10, deadline=None)
    def test_batch_permutation(self, N, gc, dc):
        X = np.round(np.random.rand(N, 10, 20, 3) * 255).astype(np.float32)
        indices = np.arange(N).astype(np.int32)
        np.random.shuffle(indices)

        quantize = core.CreateOperator("Quantize", ["X"], ["X_q"], engine="DNNLOWP")

            

Reported by Pylint.

caffe2/python/operator_test/unsafe_coalesce_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 4 Column: 1

              #!/usr/bin/env python3

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 8 Column: 1

              import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


class TestUnsafeCoalesceOp(hu.HypothesisTestCase):
    @given(
        n=st.integers(1, 5),

            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 17 Column: 49

                      shape=st.lists(st.integers(0, 5), min_size=1, max_size=3),
        **hu.gcs
    )
    def test_unsafe_coalesce_op(self, n, shape, dc, gc):
        workspace.ResetWorkspace()
        test_inputs = [(100 * np.random.random(shape)).astype(np.float32) for _ in range(n)]
        test_input_blobs = ["x_{}".format(i) for i in range(n)]

        coalesce_op = core.CreateOperator(

            

Reported by Pylint.

Using deprecated method assertEquals()
Error

Line: 30 Column: 13

                      )

        def reference_func(*args):
            self.assertEquals(len(args), n)
            return list(args) + [np.concatenate([x.flatten() for x in args])]

        self.assertReferenceChecks(gc, coalesce_op, test_inputs, reference_func)

    @given(

            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 41 Column: 68

                      seed=st.integers(0, 65535),
        **hu.gcs
    )
    def test_unsafe_coalesce_op_blob_sharing(self, n, shape, seed, dc, gc):
        workspace.ResetWorkspace()
        # Can make debugging of the test more predictable
        np.random.seed(seed)
        test_inputs = [(np.random.random(shape)).astype(np.float32) for _ in range(n)]
        test_input_blobs = ["x_{}".format(i) for i in range(n)]

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import caffe2.python.hypothesis_test_util as hu
import hypothesis.strategies as st
import numpy as np
import numpy.testing as npt
from caffe2.python import core, workspace
from hypothesis import given


            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              from hypothesis import given


class TestUnsafeCoalesceOp(hu.HypothesisTestCase):
    @given(
        n=st.integers(1, 5),
        shape=st.lists(st.integers(0, 5), min_size=1, max_size=3),
        **hu.gcs
    )

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

                      n=st.integers(1, 5),
        shape=st.lists(st.integers(0, 5), min_size=1, max_size=3),
        **hu.gcs
    )
    def test_unsafe_coalesce_op(self, n, shape, dc, gc):
        workspace.ResetWorkspace()
        test_inputs = [(100 * np.random.random(shape)).astype(np.float32) for _ in range(n)]
        test_input_blobs = ["x_{}".format(i) for i in range(n)]


            

Reported by Pylint.

Argument name "n" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

                      n=st.integers(1, 5),
        shape=st.lists(st.integers(0, 5), min_size=1, max_size=3),
        **hu.gcs
    )
    def test_unsafe_coalesce_op(self, n, shape, dc, gc):
        workspace.ResetWorkspace()
        test_inputs = [(100 * np.random.random(shape)).astype(np.float32) for _ in range(n)]
        test_input_blobs = ["x_{}".format(i) for i in range(n)]


            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

                      n=st.integers(1, 5),
        shape=st.lists(st.integers(0, 5), min_size=1, max_size=3),
        **hu.gcs
    )
    def test_unsafe_coalesce_op(self, n, shape, dc, gc):
        workspace.ResetWorkspace()
        test_inputs = [(100 * np.random.random(shape)).astype(np.float32) for _ in range(n)]
        test_input_blobs = ["x_{}".format(i) for i in range(n)]


            

Reported by Pylint.

caffe2/python/operator_test/elementwise_linear_op_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 9 Column: 1

              from caffe2.python import core
import caffe2.python.hypothesis_test_util as hu
import caffe2.python.serialized_test.serialized_test_util as serial
import hypothesis.strategies as st
import numpy as np


class TestElementwiseLinearOp(serial.SerializedTestCase):


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import core
import caffe2.python.hypothesis_test_util as hu
import caffe2.python.serialized_test.serialized_test_util as serial
import hypothesis.strategies as st

            

Reported by Pylint.

Missing class docstring
Error

Line: 13 Column: 1

              import numpy as np


class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)

            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

              class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 5

              class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)


            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

              class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)


            

Reported by Pylint.

Argument name "d" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

              class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)


            

Reported by Pylint.

Argument name "n" doesn't conform to snake_case naming style
Error

Line: 16 Column: 5

              class TestElementwiseLinearOp(serial.SerializedTestCase):

    @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)


            

Reported by Pylint.

Variable name "X" doesn't conform to snake_case naming style
Error

Line: 18 Column: 9

                  @serial.given(n=st.integers(2, 100), d=st.integers(2, 10), **hu.gcs)
    # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)

        def ref_op(X, a, b):
            d = a.shape[0]

            

Reported by Pylint.

Variable name "a" doesn't conform to snake_case naming style
Error

Line: 19 Column: 9

                  # @given(n=st.integers(2, 50), d=st.integers(2, 50), **hu.gcs_cpu_only)
    def test(self, n, d, gc, dc):
        X = np.random.rand(n, d).astype(np.float32)
        a = np.random.rand(d).astype(np.float32)
        b = np.random.rand(d).astype(np.float32)

        def ref_op(X, a, b):
            d = a.shape[0]
            return [np.multiply(X, a.reshape(1, d)) + b.reshape(1, d)]

            

Reported by Pylint.

test/distributed/elastic/rendezvous/rendezvous_backend_test.py
16 issues
Unable to import 'torch.distributed.elastic.rendezvous'
Error

Line: 10 Column: 1

              from abc import ABC, abstractmethod
from typing import Any, Callable, Optional, Tuple, cast

from torch.distributed.elastic.rendezvous import RendezvousStateError
from torch.distributed.elastic.rendezvous.dynamic_rendezvous import RendezvousBackend, Token


class RendezvousBackendTestMixin(ABC):
    _backend: RendezvousBackend

            

Reported by Pylint.

Unable to import 'torch.distributed.elastic.rendezvous.dynamic_rendezvous'
Error

Line: 11 Column: 1

              from typing import Any, Callable, Optional, Tuple, cast

from torch.distributed.elastic.rendezvous import RendezvousStateError
from torch.distributed.elastic.rendezvous.dynamic_rendezvous import RendezvousBackend, Token


class RendezvousBackendTestMixin(ABC):
    _backend: RendezvousBackend


            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 27 Column: 9

                  @abstractmethod
    def _corrupt_state(self) -> None:
        """Corrupts the state stored in the backend."""
        pass

    def _set_state(self, state: bytes, token: Optional[Any] = None) -> Tuple[bytes, Token, bool]:
        result = self._backend.set_state(state, token)

        self.assertIsNotNone(result)

            

Reported by Pylint.

Unused variable 'state1'
Error

Line: 67 Column: 9

                      self.assertTrue(has_set)

    def test_set_state_sets_backend_state_if_token_is_current(self) -> None:
        state1, token1, has_set1 = self._set_state(b"x")

        state2, token2, has_set2 = self._set_state(b"y", token1)

        self.assertEqual(b"y", state2)
        self.assertNotEqual(token1, token2)

            

Reported by Pylint.

Unused variable 'state1'
Error

Line: 77 Column: 9

                      self.assertTrue(has_set2)

    def test_set_state_returns_current_backend_state_if_token_is_old(self) -> None:
        state1, token1, _ = self._set_state(b"x")

        state2, token2, _ = self._set_state(b"y", token1)

        state3, token3, has_set = self._set_state(b"z", token1)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

from abc import ABC, abstractmethod
from typing import Any, Callable, Optional, Tuple, cast


            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              from torch.distributed.elastic.rendezvous.dynamic_rendezvous import RendezvousBackend, Token


class RendezvousBackendTestMixin(ABC):
    _backend: RendezvousBackend

    # Type hints
    assertEqual: Callable
    assertNotEqual: Callable

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

              
        return cast(Tuple[bytes, Token, bool], result)

    def test_get_state_returns_backend_state(self) -> None:
        self._backend.set_state(b"x")

        result = self._backend.get_state()

        self.assertIsNotNone(result)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 48 Column: 5

                      self.assertEqual(b"x", state)
        self.assertIsNotNone(token)

    def test_get_state_returns_none_if_backend_state_does_not_exist(self) -> None:
        result = self._backend.get_state()

        self.assertIsNone(result)

    def test_get_state_raises_error_if_backend_state_is_corrupt(self) -> None:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 5

              
        self.assertIsNone(result)

    def test_get_state_raises_error_if_backend_state_is_corrupt(self) -> None:
        self._corrupt_state()

        with self.assertRaises(RendezvousStateError):
            self._backend.get_state()


            

Reported by Pylint.

caffe2/python/test/inference_lstm_op_test.py
16 issues
Unable to import 'hypothesis.strategies'
Error

Line: 3 Column: 1

              #!/usr/bin/env python3

import hypothesis.strategies as st
import numpy as np
import torch
from caffe2.python import core
from caffe2.python.test_util import TestCase
from hypothesis import given, settings
from torch import nn

            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 8 Column: 1

              import torch
from caffe2.python import core
from caffe2.python.test_util import TestCase
from hypothesis import given, settings
from torch import nn


class TestC2LSTM(TestCase):
    @given(

            

Reported by Pylint.

Module 'torch' has no 'from_numpy' member
Error

Line: 53 Column: 30

                      else:
            inputs = np.random.randn(seq_lens, bsz, emb_lens).astype(np.float32)

        py_results = py_lstm(torch.from_numpy(inputs))
        lstm_in = [
            torch.from_numpy(inputs),
            torch.from_numpy(hx),
            torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

            

Reported by Pylint.

Module 'torch' has no 'from_numpy' member
Error

Line: 55 Column: 13

              
        py_results = py_lstm(torch.from_numpy(inputs))
        lstm_in = [
            torch.from_numpy(inputs),
            torch.from_numpy(hx),
            torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

        c2_results = torch.ops._caffe2.InferenceLSTM(

            

Reported by Pylint.

Module 'torch' has no 'from_numpy' member
Error

Line: 56 Column: 13

                      py_results = py_lstm(torch.from_numpy(inputs))
        lstm_in = [
            torch.from_numpy(inputs),
            torch.from_numpy(hx),
            torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

        c2_results = torch.ops._caffe2.InferenceLSTM(
            lstm_in, num_layers, has_biases, batch_first, is_bidirectional

            

Reported by Pylint.

Module 'torch' has no 'from_numpy' member
Error

Line: 57 Column: 13

                      lstm_in = [
            torch.from_numpy(inputs),
            torch.from_numpy(hx),
            torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

        c2_results = torch.ops._caffe2.InferenceLSTM(
            lstm_in, num_layers, has_biases, batch_first, is_bidirectional
        )

            

Reported by Pylint.

Unused variable 'net'
Error

Line: 35 Column: 9

                      is_bidirectional,
        batch_first,
    ):
        net = core.Net("test_net")
        num_directions = 2 if is_bidirectional else 1
        py_lstm = nn.LSTM(
            emb_lens,
            hidden_size,
            batch_first=batch_first,

            

Reported by Pylint.

Access to a protected member _flat_weights of a client class
Error

Line: 58 Column: 42

                          torch.from_numpy(inputs),
            torch.from_numpy(hx),
            torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

        c2_results = torch.ops._caffe2.InferenceLSTM(
            lstm_in, num_layers, has_biases, batch_first, is_bidirectional
        )


            

Reported by Pylint.

Access to a protected member _caffe2 of a client class
Error

Line: 60 Column: 22

                          torch.from_numpy(hx),
        ] + [param.detach() for param in py_lstm._flat_weights]

        c2_results = torch.ops._caffe2.InferenceLSTM(
            lstm_in, num_layers, has_biases, batch_first, is_bidirectional
        )

        np.testing.assert_array_almost_equal(
            py_results[0].detach().numpy(), c2_results[0].detach().numpy()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import hypothesis.strategies as st
import numpy as np
import torch
from caffe2.python import core
from caffe2.python.test_util import TestCase
from hypothesis import given, settings
from torch import nn

            

Reported by Pylint.

caffe2/python/operator_test/cast_op_test.py
16 issues
Unable to import 'hypothesis'
Error

Line: 10 Column: 1

              from caffe2.python import core, workspace
import caffe2.python.hypothesis_test_util as hu

from hypothesis import given
import numpy as np


class TestCastOp(hu.HypothesisTestCase):


            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 35 Column: 49

                      self.assertGradientChecks(gc, op, [data], 0, [0])

    @given(data=hu.tensor(dtype=np.int32), **hu.gcs_cpu_only)
    def test_cast_int_to_string(self, data, gc, dc):
        op = core.CreateOperator(
            'Cast', 'data', 'data_cast', to=core.DataType.STRING)

        def ref(data):
            ret = data.astype(dtype=np.str)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              





from caffe2.python import core, workspace
import caffe2.python.hypothesis_test_util as hu


            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              import numpy as np


class TestCastOp(hu.HypothesisTestCase):

    @given(**hu.gcs)
    def test_cast_int_float(self, gc, dc):
        data = np.random.rand(5, 5).astype(np.int32)
        # from int to float

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 17 Column: 5

              class TestCastOp(hu.HypothesisTestCase):

    @given(**hu.gcs)
    def test_cast_int_float(self, gc, dc):
        data = np.random.rand(5, 5).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0

            

Reported by Pylint.

Argument name "dc" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              class TestCastOp(hu.HypothesisTestCase):

    @given(**hu.gcs)
    def test_cast_int_float(self, gc, dc):
        data = np.random.rand(5, 5).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0

            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 17 Column: 5

              class TestCastOp(hu.HypothesisTestCase):

    @given(**hu.gcs)
    def test_cast_int_float(self, gc, dc):
        data = np.random.rand(5, 5).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0

            

Reported by Pylint.

Variable name "op" doesn't conform to snake_case naming style
Error

Line: 20 Column: 9

                  def test_cast_int_float(self, gc, dc):
        data = np.random.rand(5, 5).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0
        self.assertGradientChecks(gc, op, [data], 0, [0])

    @given(**hu.gcs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 5

                      self.assertGradientChecks(gc, op, [data], 0, [0])

    @given(**hu.gcs)
    def test_cast_int_float_empty(self, gc, dc):
        data = np.random.rand(0).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0

            

Reported by Pylint.

Argument name "gc" doesn't conform to snake_case naming style
Error

Line: 26 Column: 5

                      self.assertGradientChecks(gc, op, [data], 0, [0])

    @given(**hu.gcs)
    def test_cast_int_float_empty(self, gc, dc):
        data = np.random.rand(0).astype(np.int32)
        # from int to float
        op = core.CreateOperator('Cast', 'data', 'data_cast', to=1, from_type=2)
        self.assertDeviceChecks(dc, op, [data], [0])
        # This is actually 0

            

Reported by Pylint.

caffe2/python/sparse_to_dense_mask_test.py
16 issues
Missing module docstring
Error

Line: 1 Column: 1

              



from caffe2.python import core, workspace
from caffe2.python.test_util import TestCase

import numpy as np


            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              import numpy as np


class TestSparseToDenseMask(TestCase):

    def test_sparse_to_dense_mask_float(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 5

              
class TestSparseToDenseMask(TestCase):

    def test_sparse_to_dense_mask_float(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 6])

            

Reported by Pylint.

Variable name "op" doesn't conform to snake_case naming style
Error

Line: 14 Column: 9

              class TestSparseToDenseMask(TestCase):

    def test_sparse_to_dense_mask_float(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 6])
        workspace.FeedBlob(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 33 Column: 5

                      self.assertEqual(output.shape, expected.shape)
        np.testing.assert_array_equal(output, expected)

    def test_sparse_to_dense_mask_invalid_inputs(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2],

            

Reported by Pylint.

Variable name "op" doesn't conform to snake_case naming style
Error

Line: 34 Column: 9

                      np.testing.assert_array_equal(output, expected)

    def test_sparse_to_dense_mask_invalid_inputs(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2],
            max_skipped_indices=3)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 60 Column: 5

                      with self.assertRaises(RuntimeError):
            workspace.RunOperatorMultiple(op, 3)

    def test_sparse_to_dense_mask_subtensor(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 888, 6])

            

Reported by Pylint.

Variable name "op" doesn't conform to snake_case naming style
Error

Line: 61 Column: 9

                          workspace.RunOperatorMultiple(op, 3)

    def test_sparse_to_dense_mask_subtensor(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 888, 6])
        workspace.FeedBlob(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 83 Column: 5

                      self.assertEqual(output.shape, expected.shape)
        np.testing.assert_array_equal(output, expected)

    def test_sparse_to_dense_mask_string(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 6])

            

Reported by Pylint.

Variable name "op" doesn't conform to snake_case naming style
Error

Line: 84 Column: 9

                      np.testing.assert_array_equal(output, expected)

    def test_sparse_to_dense_mask_string(self):
        op = core.CreateOperator(
            'SparseToDenseMask',
            ['indices', 'values', 'default', 'lengths'],
            ['output'],
            mask=[999999999, 2, 6])
        workspace.FeedBlob(

            

Reported by Pylint.