The following issues were found

caffe2/python/rnn/rnn_cell_test_util.py
14 issues
Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import workspace, scope
from caffe2.python.model_helper import ModelHelper

import numpy as np

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              import numpy as np


def sigmoid(x):
    return 1.0 / (1.0 + np.exp(-x))


def tanh(x):
    return 2.0 * sigmoid(2.0 * x) - 1

            

Reported by Pylint.

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

Line: 12 Column: 1

              import numpy as np


def sigmoid(x):
    return 1.0 / (1.0 + np.exp(-x))


def tanh(x):
    return 2.0 * sigmoid(2.0 * x) - 1

            

Reported by Pylint.

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

Line: 16 Column: 1

                  return 1.0 / (1.0 + np.exp(-x))


def tanh(x):
    return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 16 Column: 1

                  return 1.0 / (1.0 + np.exp(-x))


def tanh(x):
    return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,

            

Reported by Pylint.

Too many local variables (24/15)
Error

Line: 20 Column: 1

                  return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,
    forget_bias, memory_optim=False,
    forward_only=False, drop_states=False, T=None,
    two_d_initial_states=None, dim_out=None,
    num_states=2,

            

Reported by Pylint.

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

Line: 20 Column: 1

                  return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,
    forget_bias, memory_optim=False,
    forward_only=False, drop_states=False, T=None,
    two_d_initial_states=None, dim_out=None,
    num_states=2,

            

Reported by Pylint.

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

Line: 20 Column: 1

                  return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,
    forget_bias, memory_optim=False,
    forward_only=False, drop_states=False, T=None,
    two_d_initial_states=None, dim_out=None,
    num_states=2,

            

Reported by Pylint.

Too many arguments (13/5)
Error

Line: 20 Column: 1

                  return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,
    forget_bias, memory_optim=False,
    forward_only=False, drop_states=False, T=None,
    two_d_initial_states=None, dim_out=None,
    num_states=2,

            

Reported by Pylint.

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

Line: 20 Column: 1

                  return 2.0 * sigmoid(2.0 * x) - 1


def _prepare_rnn(
    t, n, dim_in, create_rnn, outputs_with_grads,
    forget_bias, memory_optim=False,
    forward_only=False, drop_states=False, T=None,
    two_d_initial_states=None, dim_out=None,
    num_states=2,

            

Reported by Pylint.

caffe2/python/operator_test/assert_test.py
14 issues
Unable to import 'hypothesis'
Error

Line: 6 Column: 1

              

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



            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 7 Column: 1

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


class TestAssert(hu.HypothesisTestCase):

            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 18 Column: 45

                      shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
        **hu.gcs)
    @settings(deadline=10000)
    def test_assert(self, dtype, shape, gc, dc):
        test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))

        op = core.CreateOperator('Assert', ['X'], [])

        def assert_ref(X):

            

Reported by Pylint.

Unused argument 'X'
Error

Line: 23 Column: 24

              
        op = core.CreateOperator('Assert', ['X'], [])

        def assert_ref(X):
            return []

        try:
            self.assertReferenceChecks(gc, op, [test_tensor], assert_ref)
        except Exception:

            

Reported by Pylint.

Catching too general exception Exception
Error

Line: 28 Column: 16

              
        try:
            self.assertReferenceChecks(gc, op, [test_tensor], assert_ref)
        except Exception:
            assert(not np.all(test_tensor))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              



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

            

Reported by Pylint.

Missing class docstring
Error

Line: 12 Column: 1

              import caffe2.python.hypothesis_test_util as hu


class TestAssert(hu.HypothesisTestCase):
    @given(
        dtype=st.sampled_from(['bool_', 'int32', 'int64']),
        shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
        **hu.gcs)
    @settings(deadline=10000)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 5

                      shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
        **hu.gcs)
    @settings(deadline=10000)
    def test_assert(self, dtype, shape, gc, dc):
        test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))

        op = core.CreateOperator('Assert', ['X'], [])

        def assert_ref(X):

            

Reported by Pylint.

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

Line: 18 Column: 5

                      shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
        **hu.gcs)
    @settings(deadline=10000)
    def test_assert(self, dtype, shape, gc, dc):
        test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))

        op = core.CreateOperator('Assert', ['X'], [])

        def assert_ref(X):

            

Reported by Pylint.

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

Line: 18 Column: 5

                      shape=st.lists(elements=st.integers(1, 10), min_size=1, max_size=4),
        **hu.gcs)
    @settings(deadline=10000)
    def test_assert(self, dtype, shape, gc, dc):
        test_tensor = np.random.rand(*shape).astype(np.dtype(dtype))

        op = core.CreateOperator('Assert', ['X'], [])

        def assert_ref(X):

            

Reported by Pylint.

caffe2/python/operator_test/python_op_test.py
14 issues
Unable to import 'hypothesis'
Error

Line: 8 Column: 1

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

class PythonOpTest(hu.HypothesisTestCase):

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 9 Column: 1

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

class PythonOpTest(hu.HypothesisTestCase):
    @given(x=hu.tensor(),

            

Reported by Pylint.

Reimport 'unittest' (imported line 11)
Error

Line: 42 Column: 5

              

if __name__ == "__main__":
    import unittest
    unittest.main()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              



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

            

Reported by Pylint.

standard import "import unittest" should be placed before "from caffe2.python import core, workspace"
Error

Line: 11 Column: 1

              from hypothesis import given, settings
import hypothesis.strategies as st
import numpy as np
import unittest

class PythonOpTest(hu.HypothesisTestCase):
    @given(x=hu.tensor(),
           n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))

            

Reported by Pylint.

Missing class docstring
Error

Line: 13 Column: 1

              import numpy as np
import unittest

class PythonOpTest(hu.HypothesisTestCase):
    @given(x=hu.tensor(),
           n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))
    @settings(deadline=10000)
    def test_simple_python_op(self, x, n, w):

            

Reported by Pylint.

Method could be a function
Error

Line: 18 Column: 5

                         n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))
    @settings(deadline=10000)
    def test_simple_python_op(self, x, n, w):
        def g(input_, output):
            output[...] = input_

        def f(inputs, outputs):
            outputs[0].reshape(inputs[0].shape)

            

Reported by Pylint.

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

Line: 18 Column: 5

                         n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))
    @settings(deadline=10000)
    def test_simple_python_op(self, x, n, w):
        def g(input_, output):
            output[...] = input_

        def f(inputs, outputs):
            outputs[0].reshape(inputs[0].shape)

            

Reported by Pylint.

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

Line: 18 Column: 5

                         n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))
    @settings(deadline=10000)
    def test_simple_python_op(self, x, n, w):
        def g(input_, output):
            output[...] = input_

        def f(inputs, outputs):
            outputs[0].reshape(inputs[0].shape)

            

Reported by Pylint.

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

Line: 18 Column: 5

                         n=st.integers(min_value=1, max_value=20),
           w=st.integers(min_value=1, max_value=20))
    @settings(deadline=10000)
    def test_simple_python_op(self, x, n, w):
        def g(input_, output):
            output[...] = input_

        def f(inputs, outputs):
            outputs[0].reshape(inputs[0].shape)

            

Reported by Pylint.

caffe2/python/operator_test/index_hash_ops_test.py
14 issues
Unable to import 'hypothesis.strategies'
Error

Line: 9 Column: 1

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


class TestIndexHashOps(serial.SerializedTestCase):

            

Reported by Pylint.

Unable to import 'hypothesis'
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.strategies as st
from hypothesis import given, settings
import numpy as np


class TestIndexHashOps(serial.SerializedTestCase):
    @given(

            

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
import caffe2.python.serialized_test.serialized_test_util as serial
import hypothesis.strategies as st

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              import numpy as np


class TestIndexHashOps(serial.SerializedTestCase):
    @given(
        indices=st.sampled_from([
            np.int32, np.int64
        ]).flatmap(lambda dtype: hu.tensor(min_dim=1, max_dim=1, dtype=dtype)),
        seed=st.integers(min_value=0, max_value=10),

            

Reported by Pylint.

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

Line: 23 Column: 5

                      modulo=st.integers(min_value=100000, max_value=200000),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 5

                      modulo=st.integers(min_value=100000, max_value=200000),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []

            

Reported by Pylint.

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

Line: 23 Column: 5

                      modulo=st.integers(min_value=100000, max_value=200000),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 23 Column: 5

                      modulo=st.integers(min_value=100000, max_value=200000),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []

            

Reported by Pylint.

Consider merging these comparisons with "in" to 'dtype in (np.int32, np.int64)'
Error

Line: 27 Column: 20

                  def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []
            for index in indices:
                hashed = dtype.type(0xDEADBEEF * seed)
                indices_bytes = np.array([index], dtype).view(np.int8)
                for b in indices_bytes:

            

Reported by Pylint.

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

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

                  def test_index_hash_ops(self, indices, seed, modulo, gc, dc):
        def index_hash(indices):
            dtype = np.array(indices).dtype
            assert dtype == np.int32 or dtype == np.int64
            hashed_indices = []
            for index in indices:
                hashed = dtype.type(0xDEADBEEF * seed)
                indices_bytes = np.array([index], dtype).view(np.int8)
                for b in indices_bytes:

            

Reported by Bandit.

caffe2/python/pipeline_test.py
14 issues
Module 'caffe2.python._import_c_extension' has no 'Workspace' member
Error

Line: 65 Column: 14

                          out2 = pipe(out1, processor=proc2)
            pipe(out2, dst_ds.writer())

        ws = workspace.C.Workspace()
        FeedRecord(src_blobs, src_values, ws)
        session = LocalSession(ws)
        session.run(init_net)
        session.run(tg)
        output = FetchRecord(dst_blobs, ws=ws)

            

Reported by Pylint.

Using deprecated method assertEquals()
Error

Line: 73 Column: 9

                      output = FetchRecord(dst_blobs, ws=ws)
        num_dequeues = ws.blobs[str(counter)].fetch()

        self.assertEquals(
            num_dequeues, int(math.ceil(float(N) / NUM_DEQUEUE_RECORDS)))

        for a, b in zip(output.field_blobs(), expected_dst.field_blobs()):
            np.testing.assert_array_equal(a, b)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python.schema import (
    Struct, FetchRecord, NewRecord, FeedRecord, InitEmptyRecord)
from caffe2.python import core, workspace
from caffe2.python.session import LocalSession

            

Reported by Pylint.

standard import "import math" should be placed before "from caffe2.python.schema import Struct, FetchRecord, NewRecord, FeedRecord, InitEmptyRecord"
Error

Line: 17 Column: 1

              from caffe2.python.test_util import TestCase
from caffe2.python.net_builder import ops
import numpy as np
import math


class TestPipeline(TestCase):
    def test_dequeue_many(self):
        init_net = core.Net('init')

            

Reported by Pylint.

Missing class docstring
Error

Line: 20 Column: 1

              import math


class TestPipeline(TestCase):
    def test_dequeue_many(self):
        init_net = core.Net('init')
        N = 17
        NUM_DEQUEUE_RECORDS = 3
        src_values = Struct(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 5

              

class TestPipeline(TestCase):
    def test_dequeue_many(self):
        init_net = core.Net('init')
        N = 17
        NUM_DEQUEUE_RECORDS = 3
        src_values = Struct(
            ('uid', np.array(range(N))),

            

Reported by Pylint.

Too many local variables (23/15)
Error

Line: 21 Column: 5

              

class TestPipeline(TestCase):
    def test_dequeue_many(self):
        init_net = core.Net('init')
        N = 17
        NUM_DEQUEUE_RECORDS = 3
        src_values = Struct(
            ('uid', np.array(range(N))),

            

Reported by Pylint.

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

Line: 23 Column: 9

              class TestPipeline(TestCase):
    def test_dequeue_many(self):
        init_net = core.Net('init')
        N = 17
        NUM_DEQUEUE_RECORDS = 3
        src_values = Struct(
            ('uid', np.array(range(N))),
            ('value', 0.1 * np.array(range(N))))
        expected_dst = Struct(

            

Reported by Pylint.

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

Line: 24 Column: 9

                  def test_dequeue_many(self):
        init_net = core.Net('init')
        N = 17
        NUM_DEQUEUE_RECORDS = 3
        src_values = Struct(
            ('uid', np.array(range(N))),
            ('value', 0.1 * np.array(range(N))))
        expected_dst = Struct(
            ('uid', 2 * np.array(range(N))),

            

Reported by Pylint.

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

Line: 36 Column: 13

                          src_blobs = NewRecord(init_net, src_values)
            dst_blobs = InitEmptyRecord(init_net, src_values.clone_schema())
            counter = init_net.Const(0)
            ONE = init_net.Const(1)

        def proc1(rec):
            with core.NameScope('proc1'):
                out = NewRecord(ops, rec)
            ops.Add([rec.uid(), rec.uid()], [out.uid()])

            

Reported by Pylint.

caffe2/python/operator_test/rand_quantization_op_speed_test.py
14 issues
Unable to import 'hypothesis.strategies'
Error

Line: 6 Column: 1

              import time

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



            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 9 Column: 1

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


np.set_printoptions(precision=6)



            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 31 Column: 84

                      **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")
        sub_op = core.CreateOperator("Sub", ["X1", "X2"], ["dX"])

            

Reported by Pylint.

Unused argument 'gc'
Error

Line: 31 Column: 80

                      **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")
        sub_op = core.CreateOperator("Sub", ["X1", "X2"], ["dX"])

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              

import time

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

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              np.set_printoptions(precision=6)


class TestSpeedFloatToFusedRandRowwiseQuantized(hu.HypothesisTestCase):
    @given(
        bitwidth_=st.sampled_from([1, 2, 4, 8]),
        random_=st.sampled_from([True, False]),
        data_shape_=st.sampled_from(
            [

            

Reported by Pylint.

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

Line: 30 Column: 5

                      ),
        **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")

            

Reported by Pylint.

Too many local variables (23/15)
Error

Line: 30 Column: 5

                      ),
        **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")

            

Reported by Pylint.

Method could be a function
Error

Line: 30 Column: 5

                      ),
        **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 30 Column: 5

                      ),
        **hu.gcs
    )
    @settings(deadline=10000)
    def test_speed_of_rand_quantization(self, bitwidth_, random_, data_shape_, gc, dc):
        X1 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)
        X2 = np.random.rand(data_shape_[0], data_shape_[1]).astype(np.float32)

        sub_scale_sum_net = core.Net("sub_scale_sum")

            

Reported by Pylint.

caffe2/python/operator_test/sparse_lp_regularizer_test.py
14 issues
Unable to import 'hypothesis'
Error

Line: 6 Column: 1

              


import hypothesis
from hypothesis import given, settings, HealthCheck
import hypothesis.strategies as st
import numpy as np

from caffe2.python import core

            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 7 Column: 1

              

import hypothesis
from hypothesis import given, settings, HealthCheck
import hypothesis.strategies as st
import numpy as np

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

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 8 Column: 1

              
import hypothesis
from hypothesis import given, settings, HealthCheck
import hypothesis.strategies as st
import numpy as np

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


            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 37 Column: 76

                         reg_lambda=st.floats(min_value=1e-4, max_value=1e-1),
           data_strategy=st.data(),
           **hu.gcs_cpu_only)
    def test_sparse_lpnorm(self, inputs, p, reg_lambda, data_strategy, gc, dc):

        param, = inputs
        param += 0.02 * np.sign(param)
        param[param == 0.0] += 0.02


            

Reported by Pylint.

Unused argument 'grad'
Error

Line: 63 Column: 55

                          reg_lambda=reg_lambda,
        )

        def ref_sparse_lp_regularizer(param, indices, grad=None):
            param_out = np.copy(param)
            for _, index in enumerate(indices):
                param_out[index] = self.ref_lpnorm(
                    param[index],
                    p=p,

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import hypothesis
from hypothesis import given, settings, HealthCheck
import hypothesis.strategies as st
import numpy as np

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              import caffe2.python.hypothesis_test_util as hu


class TestSparseLpNorm(hu.HypothesisTestCase):

    @staticmethod
    def ref_lpnorm(param_in, p, reg_lambda):
        """Reference function that should be matched by the Caffe2 operator."""
        if p == 2.0:

            

Reported by Pylint.

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

Line: 18 Column: 5

              class TestSparseLpNorm(hu.HypothesisTestCase):

    @staticmethod
    def ref_lpnorm(param_in, p, reg_lambda):
        """Reference function that should be matched by the Caffe2 operator."""
        if p == 2.0:
            return param_in * (1 - reg_lambda)
        if p == 1.0:
            reg_term = np.ones_like(param_in) * reg_lambda * np.sign(param_in)

            

Reported by Pylint.

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

Line: 37 Column: 5

                         reg_lambda=st.floats(min_value=1e-4, max_value=1e-1),
           data_strategy=st.data(),
           **hu.gcs_cpu_only)
    def test_sparse_lpnorm(self, inputs, p, reg_lambda, data_strategy, gc, dc):

        param, = inputs
        param += 0.02 * np.sign(param)
        param[param == 0.0] += 0.02


            

Reported by Pylint.

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

Line: 37 Column: 5

                         reg_lambda=st.floats(min_value=1e-4, max_value=1e-1),
           data_strategy=st.data(),
           **hu.gcs_cpu_only)
    def test_sparse_lpnorm(self, inputs, p, reg_lambda, data_strategy, gc, dc):

        param, = inputs
        param += 0.02 * np.sign(param)
        param[param == 0.0] += 0.02


            

Reported by Pylint.

caffe2/python/operator_test/unique_uniform_fill_op_test.py
14 issues
Unable to import 'hypothesis'
Error

Line: 6 Column: 1

              

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

import unittest

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 8 Column: 1

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

import unittest



            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 32 Column: 69

                      s=st.integers(10, 500),
        **hu.gcs_cpu_only
    )
    def test_unique_uniform_int_fill(self, r, avoid, dtypes, s, gc, dc):
        net = core.Net("net")
        workspace.FeedBlob("X", np.array([s], dtype=np.int64))
        workspace.FeedBlob("AVOID", np.array(avoid, dtype=dtypes[0]))
        net.UniqueUniformFill(
            ["X", "AVOID"], ["Y"],

            

Reported by Pylint.

Unused argument 'gc'
Error

Line: 32 Column: 65

                      s=st.integers(10, 500),
        **hu.gcs_cpu_only
    )
    def test_unique_uniform_int_fill(self, r, avoid, dtypes, s, gc, dc):
        net = core.Net("net")
        workspace.FeedBlob("X", np.array([s], dtype=np.int64))
        workspace.FeedBlob("AVOID", np.array(avoid, dtype=dtypes[0]))
        net.UniqueUniformFill(
            ["X", "AVOID"], ["Y"],

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              



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

            

Reported by Pylint.

standard import "import unittest" should be placed before "from caffe2.python import core, workspace"
Error

Line: 11 Column: 1

              import hypothesis.strategies as st
import numpy as np

import unittest


class TestUniqueUniformFillOp(hu.HypothesisTestCase):
    @given(
        r=st.integers(1000, 10000),

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              import unittest


class TestUniqueUniformFillOp(hu.HypothesisTestCase):
    @given(
        r=st.integers(1000, 10000),
        avoid=st.lists(
            st.integers(1, 1000),
            min_size=1,

            

Reported by Pylint.

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

Line: 31 Column: 5

                      ),
        s=st.integers(10, 500),
        **hu.gcs_cpu_only
    )
    def test_unique_uniform_int_fill(self, r, avoid, dtypes, s, gc, dc):
        net = core.Net("net")
        workspace.FeedBlob("X", np.array([s], dtype=np.int64))
        workspace.FeedBlob("AVOID", np.array(avoid, dtype=dtypes[0]))
        net.UniqueUniformFill(

            

Reported by Pylint.

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

Line: 31 Column: 5

                      ),
        s=st.integers(10, 500),
        **hu.gcs_cpu_only
    )
    def test_unique_uniform_int_fill(self, r, avoid, dtypes, s, gc, dc):
        net = core.Net("net")
        workspace.FeedBlob("X", np.array([s], dtype=np.int64))
        workspace.FeedBlob("AVOID", np.array(avoid, dtype=dtypes[0]))
        net.UniqueUniformFill(

            

Reported by Pylint.

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

Line: 31 Column: 5

                      ),
        s=st.integers(10, 500),
        **hu.gcs_cpu_only
    )
    def test_unique_uniform_int_fill(self, r, avoid, dtypes, s, gc, dc):
        net = core.Net("net")
        workspace.FeedBlob("X", np.array([s], dtype=np.int64))
        workspace.FeedBlob("AVOID", np.array(avoid, dtype=dtypes[0]))
        net.UniqueUniformFill(

            

Reported by Pylint.

test/custom_backend/backend.py
14 issues
Unable to import 'torch'
Error

Line: 4 Column: 1

              import argparse
import os.path
import sys
import torch


def get_custom_backend_library_path():
    """
    Get the path to the library containing the custom backend.

            

Reported by Pylint.

Access to a protected member _jit_to_backend of a client class
Error

Line: 36 Column: 22

                  Returns:
        The module, lowered so that it can run on TestBackend.
    """
    lowered_module = torch._C._jit_to_backend("custom_backend", module, {"forward": {"": ""}})
    return lowered_module


class Model(torch.nn.Module):
    """

            

Reported by Pylint.

Access to a protected member _C of a client class
Error

Line: 36 Column: 22

                  Returns:
        The module, lowered so that it can run on TestBackend.
    """
    lowered_module = torch._C._jit_to_backend("custom_backend", module, {"forward": {"": ""}})
    return lowered_module


class Model(torch.nn.Module):
    """

            

Reported by Pylint.

Useless super delegation in method '__init__'
Error

Line: 46 Column: 5

                  and executing in C++.
    """

    def __init__(self):
        super(Model, self).__init__()

    def forward(self, a, b):
        return (a + b, a - b)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import argparse
import os.path
import sys
import torch


def get_custom_backend_library_path():
    """
    Get the path to the library containing the custom backend.

            

Reported by Pylint.

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

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

                  else:
        library_filename = "libcustom_backend.so"
    path = os.path.abspath("build/{}".format(library_filename))
    assert os.path.exists(path), path
    return path


def to_custom_backend(module):
    """

            

Reported by Bandit.

Too few public methods (1/2)
Error

Line: 40 Column: 1

                  return lowered_module


class Model(torch.nn.Module):
    """
    Simple model used for testing that to_backend API supports saving, loading,
    and executing in C++.
    """


            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 47 Column: 9

                  """

    def __init__(self):
        super(Model, self).__init__()

    def forward(self, a, b):
        return (a + b, a - b)



            

Reported by Pylint.

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

Line: 49 Column: 5

                  def __init__(self):
        super(Model, self).__init__()

    def forward(self, a, b):
        return (a + b, a - b)


def main():
    parser = argparse.ArgumentParser(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 49 Column: 5

                  def __init__(self):
        super(Model, self).__init__()

    def forward(self, a, b):
        return (a + b, a - b)


def main():
    parser = argparse.ArgumentParser(

            

Reported by Pylint.

caffe2/python/operator_test/sinusoid_position_encoding_op_test.py
14 issues
Unable to import 'hypothesis'
Error

Line: 7 Column: 1

              

from caffe2.python import core
from hypothesis import given, settings
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
import math

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 10 Column: 1

              from hypothesis import given, settings
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
import math

MAX_TEST_EMBEDDING_SIZE = 20
MAX_TEST_SEQUENCE_LENGTH = 10

            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 38 Column: 80

                  )
    @settings(deadline=10000)
    def test_sinusoid_embedding(
        self, positions_vec, embedding_size, batch_size, alpha, amplitude, gc, dc
    ):
        positions = np.tile(positions_vec, [batch_size, 1]).transpose()

        op = core.CreateOperator(
            "SinusoidPositionEncoding",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




from caffe2.python import core
from hypothesis import given, settings
import caffe2.python.hypothesis_test_util as hu
import caffe2.python.serialized_test.serialized_test_util as serial

            

Reported by Pylint.

standard import "import math" should be placed before "from caffe2.python import core"
Error

Line: 12 Column: 1

              import caffe2.python.serialized_test.serialized_test_util as serial
import hypothesis.strategies as st
import numpy as np
import math

MAX_TEST_EMBEDDING_SIZE = 20
MAX_TEST_SEQUENCE_LENGTH = 10
MAX_TEST_BATCH_SIZE = 5
MIN_TEST_ALPHA = 5000.0

            

Reported by Pylint.

Missing class docstring
Error

Line: 23 Column: 1

              MAX_TEST_AMPLITUDE = 10.0


class TestSinusoidPositionEncodingOp(serial.SerializedTestCase):
    @given(
        positions_vec=hu.arrays(
            dims=[MAX_TEST_SEQUENCE_LENGTH],
            dtype=np.int32,
            elements=st.integers(1, MAX_TEST_SEQUENCE_LENGTH)

            

Reported by Pylint.

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

Line: 36 Column: 5

                      amplitude=st.floats(MIN_TEST_AMPLITUDE, MAX_TEST_AMPLITUDE),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_sinusoid_embedding(
        self, positions_vec, embedding_size, batch_size, alpha, amplitude, gc, dc
    ):
        positions = np.tile(positions_vec, [batch_size, 1]).transpose()


            

Reported by Pylint.

Too many arguments (8/5)
Error

Line: 36 Column: 5

                      amplitude=st.floats(MIN_TEST_AMPLITUDE, MAX_TEST_AMPLITUDE),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_sinusoid_embedding(
        self, positions_vec, embedding_size, batch_size, alpha, amplitude, gc, dc
    ):
        positions = np.tile(positions_vec, [batch_size, 1]).transpose()


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 5

                      amplitude=st.floats(MIN_TEST_AMPLITUDE, MAX_TEST_AMPLITUDE),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_sinusoid_embedding(
        self, positions_vec, embedding_size, batch_size, alpha, amplitude, gc, dc
    ):
        positions = np.tile(positions_vec, [batch_size, 1]).transpose()


            

Reported by Pylint.

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

Line: 36 Column: 5

                      amplitude=st.floats(MIN_TEST_AMPLITUDE, MAX_TEST_AMPLITUDE),
        **hu.gcs_cpu_only
    )
    @settings(deadline=10000)
    def test_sinusoid_embedding(
        self, positions_vec, embedding_size, batch_size, alpha, amplitude, gc, dc
    ):
        positions = np.tile(positions_vec, [batch_size, 1]).transpose()


            

Reported by Pylint.