The following issues were found

caffe2/python/ideep/sigmoid_op_test.py
10 issues
Unable to import 'hypothesis.strategies'
Error

Line: 7 Column: 1

              

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


            

Reported by Pylint.

Unable to import 'hypothesis'
Error

Line: 8 Column: 1

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



            

Reported by Pylint.

Module 'caffe2.python._import_c_extension' has no 'use_mkldnn' member
Error

Line: 14 Column: 22

              import caffe2.python.hypothesis_test_util as hu


@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class SigmoidTest(hu.HypothesisTestCase):
    @given(X=hu.tensor(dtype=np.float32),
           inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




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

            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

              

@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class SigmoidTest(hu.HypothesisTestCase):
    @given(X=hu.tensor(dtype=np.float32),
           inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):

            

Reported by Pylint.

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

Line: 20 Column: 5

                         inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):
        op = core.CreateOperator(
            "Sigmoid",
            ["X"],
            ["Y"] if not inplace else ["X"],
        )

            

Reported by Pylint.

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

Line: 20 Column: 5

                         inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):
        op = core.CreateOperator(
            "Sigmoid",
            ["X"],
            ["Y"] if not inplace else ["X"],
        )

            

Reported by Pylint.

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

Line: 20 Column: 5

                         inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):
        op = core.CreateOperator(
            "Sigmoid",
            ["X"],
            ["Y"] if not inplace else ["X"],
        )

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 5

                         inplace=st.booleans(),
           **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):
        op = core.CreateOperator(
            "Sigmoid",
            ["X"],
            ["Y"] if not inplace else ["X"],
        )

            

Reported by Pylint.

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

Line: 21 Column: 9

                         **hu.gcs)
    @settings(deadline=1000)
    def test_sigmoid(self, X, inplace, gc, dc):
        op = core.CreateOperator(
            "Sigmoid",
            ["X"],
            ["Y"] if not inplace else ["X"],
        )


            

Reported by Pylint.

caffe2/contrib/playground/resnetdemo/gfs_IN1k.py
10 issues
Unused argument 'dataset'
Error

Line: 8 Column: 40

              
# # example1 using gfs as input source.

def gen_input_builder_fun(self, model, dataset, is_train):
    if is_train:
        input_path = self.opts['input']['train_input_path']
    else:
        input_path = self.opts['input']['test_input_path']


            

Reported by Pylint.

Unused variable 'label'
Error

Line: 25 Column: 15

                      Image input operator that loads data from reader and
        applies certain transformations to the images.
        '''
        data, label = model.ImageInput(
            reader,
            ["data", "label"],
            batch_size=batch_size,
            use_caffe_datum=True,
            mean=128.,

            

Reported by Pylint.

Unused argument 'opts'
Error

Line: 49 Column: 23

                  return add_image_input


def get_input_dataset(opts):
    return []


def get_model_input_fun(self):
    pass

            

Reported by Pylint.

Unused argument 'self'
Error

Line: 53 Column: 25

                  return []


def get_model_input_fun(self):
    pass

            

Reported by Pylint.

Module name "gfs_IN1k" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              




# # example1 using gfs as input source.

def gen_input_builder_fun(self, model, dataset, is_train):
    if is_train:

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




# # example1 using gfs as input source.

def gen_input_builder_fun(self, model, dataset, is_train):
    if is_train:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              
# # example1 using gfs as input source.

def gen_input_builder_fun(self, model, dataset, is_train):
    if is_train:
        input_path = self.opts['input']['train_input_path']
    else:
        input_path = self.opts['input']['test_input_path']


            

Reported by Pylint.

Function name "AddImageInput" doesn't conform to snake_case naming style
Error

Line: 20 Column: 5

                                          shard_id=self.shard_id,
                            num_shards=self.opts['distributed']['num_shards'],)

    def AddImageInput(model, reader, batch_size, img_size):
        '''
        Image input operator that loads data from reader and
        applies certain transformations to the images.
        '''
        data, label = model.ImageInput(

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 49 Column: 1

                  return add_image_input


def get_input_dataset(opts):
    return []


def get_model_input_fun(self):
    pass

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 1

                  return []


def get_model_input_fun(self):
    pass

            

Reported by Pylint.

caffe2/python/ideep/blobs_queue_db_test.py
10 issues
Unable to import 'caffe2.proto.caffe2_pb2'
Error

Line: 9 Column: 1

              import unittest
import numpy as np

import caffe2.proto.caffe2_pb2 as caffe2_pb2
from caffe2.python import core, workspace, timeout_guard


@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class BlobsQueueDBTest(unittest.TestCase):

            

Reported by Pylint.

Module 'caffe2.python._import_c_extension' has no 'use_mkldnn' member
Error

Line: 13 Column: 22

              from caffe2.python import core, workspace, timeout_guard


@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class BlobsQueueDBTest(unittest.TestCase):
    def test_create_blobs_queue_db_string(self):
        device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            def add_blobs(queue, num_samples):

            

Reported by Pylint.

Reimport 'unittest' (imported line 6)
Error

Line: 108 Column: 5

                      return item.SerializeToString()

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

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import unittest
import numpy as np

import caffe2.proto.caffe2_pb2 as caffe2_pb2

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              

@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class BlobsQueueDBTest(unittest.TestCase):
    def test_create_blobs_queue_db_string(self):
        device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            def add_blobs(queue, num_samples):
                blob = core.BlobReference("blob")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

              
@unittest.skipIf(not workspace.C.use_mkldnn, "No MKLDNN support.")
class BlobsQueueDBTest(unittest.TestCase):
    def test_create_blobs_queue_db_string(self):
        device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            def add_blobs(queue, num_samples):
                blob = core.BlobReference("blob")
                status = core.BlobReference("blob_status")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 5

                                  )
            self._test_create_blobs_queue_db(add_blobs)

    def test_create_blobs_queue_db_tensor(self):
        device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            def add_blobs(queue, num_samples):
                blob = core.BlobReference("blob")
                status = core.BlobReference("blob_status")

            

Reported by Pylint.

Method could be a function
Error

Line: 84 Column: 5

                                  self.assertEqual(1, item)
            workspace.RunNetOnce(close_net)

    def _add_blob_to_queue(self, queue, data, blob, status):
        device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            workspace.FeedBlob(blob, data, core.DeviceOption(caffe2_pb2.CPU, 0))
            op = core.CreateOperator(
                "SafeEnqueueBlobs",

            

Reported by Pylint.

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

Line: 88 Column: 13

                      device_opt = core.DeviceOption(caffe2_pb2.IDEEP, 0)
        with core.DeviceScope(device_opt):
            workspace.FeedBlob(blob, data, core.DeviceOption(caffe2_pb2.CPU, 0))
            op = core.CreateOperator(
                "SafeEnqueueBlobs",
                [queue, blob],
                [blob, status],
            )


            

Reported by Pylint.

Method could be a function
Error

Line: 96 Column: 5

              
            workspace.RunOperatorOnce(op)

    def _create_test_tensor_protos(self, idx):
        item = caffe2_pb2.TensorProtos()
        data = item.protos.add()
        data.data_type = core.DataType.STRING
        data.string_data.append("foo{}".format(idx).encode('utf-8'))
        label = item.protos.add()

            

Reported by Pylint.

caffe2/quantization/server/relu_dnnlowp_op_test.py
10 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: 19 Column: 53

              
class DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0
        max_ = 10.0
        scale = (max_ - min_) / 255

            

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 DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0

            

Reported by Pylint.

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

Line: 19 Column: 5

              
class DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0
        max_ = 10.0
        scale = (max_ - min_) / 255

            

Reported by Pylint.

Too many local variables (19/15)
Error

Line: 19 Column: 5

              
class DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0
        max_ = 10.0
        scale = (max_ - min_) / 255

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 5

              
class DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0
        max_ = 10.0
        scale = (max_ - min_) / 255

            

Reported by Pylint.

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

Line: 19 Column: 5

              
class DNNLowPReluOpTest(hu.HypothesisTestCase):
    @given(size=st.integers(1024, 2048), is_empty=st.booleans(), **hu.gcs_cpu_only)
    def test_dnnlowp_relu(self, size, is_empty, gc, dc):
        if is_empty:
            size = 0
        min_ = -10.0
        max_ = 10.0
        scale = (max_ - min_) / 255

            

Reported by Pylint.

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

Line: 26 Column: 9

                      max_ = 10.0
        scale = (max_ - min_) / 255
        zero_point = int(np.round(-min_ / scale))
        X = (np.random.rand(size) * (max_ - min_) + min_).astype(np.float32)

        Output = collections.namedtuple("Output", ["Y", "op_type", "engine"])
        outputs = []

        op_engine_list = [("Relu", ""), ("Relu", "DNNLOWP"), ("Int8Relu", "DNNLOWP")]

            

Reported by Pylint.

caffe2/python/operator_test/lengths_pad_op_test.py
10 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 TestLengthsPadOp(serial.SerializedTestCase):


            

Reported by Pylint.

Unused argument 'dc'
Error

Line: 26 Column: 73

                      padding_value=st.floats(-10.0, 10.0),
        **hu.gcs
    )
    def test_lengths_pad(self, inputs, delta_length, padding_value, gc, dc):
        data, lengths = inputs
        max_length = np.max(lengths) if len(lengths) > 0 else 0
        target_length = max(max_length + delta_length, 1)

        def lengths_pad_op(data, lengths):

            

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 TestLengthsPadOp(serial.SerializedTestCase):

    @serial.given(
        inputs=hu.lengths_tensor(
            dtype=np.float32,
            min_value=1,

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 25 Column: 5

                      delta_length=st.integers(0, 10),
        padding_value=st.floats(-10.0, 10.0),
        **hu.gcs
    )
    def test_lengths_pad(self, inputs, delta_length, padding_value, gc, dc):
        data, lengths = inputs
        max_length = np.max(lengths) if len(lengths) > 0 else 0
        target_length = max(max_length + delta_length, 1)


            

Reported by Pylint.

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

Line: 25 Column: 5

                      delta_length=st.integers(0, 10),
        padding_value=st.floats(-10.0, 10.0),
        **hu.gcs
    )
    def test_lengths_pad(self, inputs, delta_length, padding_value, gc, dc):
        data, lengths = inputs
        max_length = np.max(lengths) if len(lengths) > 0 else 0
        target_length = max(max_length + delta_length, 1)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 25 Column: 5

                      delta_length=st.integers(0, 10),
        padding_value=st.floats(-10.0, 10.0),
        **hu.gcs
    )
    def test_lengths_pad(self, inputs, delta_length, padding_value, gc, dc):
        data, lengths = inputs
        max_length = np.max(lengths) if len(lengths) > 0 else 0
        target_length = max(max_length + delta_length, 1)


            

Reported by Pylint.

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

Line: 25 Column: 5

                      delta_length=st.integers(0, 10),
        padding_value=st.floats(-10.0, 10.0),
        **hu.gcs
    )
    def test_lengths_pad(self, inputs, delta_length, padding_value, gc, dc):
        data, lengths = inputs
        max_length = np.max(lengths) if len(lengths) > 0 else 0
        target_length = max(max_length + delta_length, 1)


            

Reported by Pylint.

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

Line: 32 Column: 13

                      target_length = max(max_length + delta_length, 1)

        def lengths_pad_op(data, lengths):
            N = len(lengths)
            output = np.ndarray(
                shape=(target_length * N, ) + data.shape[1:], dtype=np.float32)
            output.fill(padding_value)
            ptr1, ptr2 = 0, 0
            for i in range(N):

            

Reported by Pylint.

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

Line: 44 Column: 9

              
            return [output]

        op = core.CreateOperator(
            "LengthsPad",
            ["data", "lengths"],
            ["data_padded"],
            target_length=target_length,
            padding_value=padding_value,

            

Reported by Pylint.

test/bottleneck_test/test_cuda.py
10 issues
Unable to import 'torch'
Error

Line: 1 Column: 1

              import torch
import torch.nn as nn


class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)


            

Reported by Pylint.

Unable to import 'torch.nn'
Error

Line: 2 Column: 1

              import torch
import torch.nn as nn


class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)


            

Reported by Pylint.

Redefining built-in 'input'
Error

Line: 10 Column: 23

                      super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)

    def forward(self, input):
        out = self.linear(input[:, 10:30])
        return out.sum()


def main():

            

Reported by Pylint.

Unused variable 'i'
Error

Line: 19 Column: 9

                  data = torch.randn(10, 50).cuda()
    model = Model().cuda()
    optimizer = torch.optim.SGD(model.parameters(), lr=0.0001)
    for i in range(10):
        optimizer.zero_grad()
        loss = model(data)
        loss.backward()
        optimizer.step()


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import torch
import torch.nn as nn


class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)


            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 5 Column: 1

              import torch.nn as nn


class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)

    def forward(self, input):

            

Reported by Pylint.

Missing class docstring
Error

Line: 5 Column: 1

              import torch.nn as nn


class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)

    def forward(self, input):

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 7 Column: 9

              
class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)

    def forward(self, input):
        out = self.linear(input[:, 10:30])
        return out.sum()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

                      super(Model, self).__init__()
        self.linear = nn.Linear(20, 20)

    def forward(self, input):
        out = self.linear(input[:, 10:30])
        return out.sum()


def main():

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

                      return out.sum()


def main():
    data = torch.randn(10, 50).cuda()
    model = Model().cuda()
    optimizer = torch.optim.SGD(model.parameters(), lr=0.0001)
    for i in range(10):
        optimizer.zero_grad()

            

Reported by Pylint.

test/distributed/launcher/launch_test.py
10 issues
Unable to import 'torch.distributed.launch'
Error

Line: 14 Column: 1

              import unittest
from contextlib import closing

import torch.distributed.launch as launch
from torch.distributed.elastic.utils import get_socket_with_port
from torch.testing._internal.common_utils import (
    TEST_WITH_DEV_DBG_ASAN,
    TEST_WITH_TSAN,
    sandcastle_skip_if,

            

Reported by Pylint.

Unable to import 'torch.distributed.elastic.utils'
Error

Line: 15 Column: 1

              from contextlib import closing

import torch.distributed.launch as launch
from torch.distributed.elastic.utils import get_socket_with_port
from torch.testing._internal.common_utils import (
    TEST_WITH_DEV_DBG_ASAN,
    TEST_WITH_TSAN,
    sandcastle_skip_if,
)

            

Reported by Pylint.

Unable to import 'torch.testing._internal.common_utils'
Error

Line: 16 Column: 1

              
import torch.distributed.launch as launch
from torch.distributed.elastic.utils import get_socket_with_port
from torch.testing._internal.common_utils import (
    TEST_WITH_DEV_DBG_ASAN,
    TEST_WITH_TSAN,
    sandcastle_skip_if,
)


            

Reported by Pylint.

Unused variable 'world_size'
Error

Line: 44 Column: 9

                  def test_launch_without_env(self):
        nnodes = 1
        nproc_per_node = 4
        world_size = nnodes * nproc_per_node
        sock = get_socket_with_port()
        with closing(sock):
            master_port = sock.getsockname()[1]
        args = [
            f"--nnodes={nnodes}",

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

# 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.
import os
import shutil

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

              )


def path(script):
    return os.path.join(os.path.dirname(__file__), script)


class LaunchTest(unittest.TestCase):
    def setUp(self):

            

Reported by Pylint.

Missing class docstring
Error

Line: 27 Column: 1

                  return os.path.join(os.path.dirname(__file__), script)


class LaunchTest(unittest.TestCase):
    def setUp(self):
        self.test_dir = tempfile.mkdtemp()
        # set a sentinel env var on the parent proc
        # this should be present on the child and gets
        # asserted in ``bin/test_script.py``

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 5

              
    @sandcastle_skip_if(
        TEST_WITH_DEV_DBG_ASAN or TEST_WITH_TSAN, "tests incompatible with tsan and dev/dbg asan"
    )
    def test_launch_without_env(self):
        nnodes = 1
        nproc_per_node = 4
        world_size = nnodes * nproc_per_node
        sock = get_socket_with_port()

            

Reported by Pylint.

Method could be a function
Error

Line: 40 Column: 5

              
    @sandcastle_skip_if(
        TEST_WITH_DEV_DBG_ASAN or TEST_WITH_TSAN, "tests incompatible with tsan and dev/dbg asan"
    )
    def test_launch_without_env(self):
        nnodes = 1
        nproc_per_node = 4
        world_size = nnodes * nproc_per_node
        sock = get_socket_with_port()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 62 Column: 5

              
    @sandcastle_skip_if(
        TEST_WITH_DEV_DBG_ASAN or TEST_WITH_TSAN, "tests incompatible with tsan and dev/dbg asan"
    )
    def test_launch_with_env(self):
        nnodes = 1
        nproc_per_node = 4
        world_size = nnodes * nproc_per_node
        sock = get_socket_with_port()

            

Reported by Pylint.

caffe2/python/operator_test/weighted_sample_test.py
10 issues
Unable to import 'hypothesis'
Error

Line: 8 Column: 1

              
import numpy as np

from hypothesis import given
import hypothesis.strategies as st

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

            

Reported by Pylint.

Unable to import 'hypothesis.strategies'
Error

Line: 9 Column: 1

              import numpy as np

from hypothesis import given
import hypothesis.strategies as st

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


            

Reported by Pylint.

Unused argument 'gc'
Error

Line: 22 Column: 56

                      weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )
    def test_weighted_sample(self, batch, weights_len, gc, dc):

        weights = np.zeros((batch, weights_len))
        values = np.zeros((batch, weights_len))
        rand_indices = []
        rand_values = []

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              




import numpy as np

from hypothesis import given
import hypothesis.strategies as st

            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

              import caffe2.python.hypothesis_test_util as hu


class TestWeightedSample(hu.HypothesisTestCase):
    @given(
        batch=st.integers(min_value=0, max_value=128),
        weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )

            

Reported by Pylint.

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

Line: 21 Column: 5

                      batch=st.integers(min_value=0, max_value=128),
        weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )
    def test_weighted_sample(self, batch, weights_len, gc, dc):

        weights = np.zeros((batch, weights_len))
        values = np.zeros((batch, weights_len))
        rand_indices = []

            

Reported by Pylint.

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

Line: 21 Column: 5

                      batch=st.integers(min_value=0, max_value=128),
        weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )
    def test_weighted_sample(self, batch, weights_len, gc, dc):

        weights = np.zeros((batch, weights_len))
        values = np.zeros((batch, weights_len))
        rand_indices = []

            

Reported by Pylint.

Too many local variables (17/15)
Error

Line: 21 Column: 5

                      batch=st.integers(min_value=0, max_value=128),
        weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )
    def test_weighted_sample(self, batch, weights_len, gc, dc):

        weights = np.zeros((batch, weights_len))
        values = np.zeros((batch, weights_len))
        rand_indices = []

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 5

                      batch=st.integers(min_value=0, max_value=128),
        weights_len=st.integers(min_value=0, max_value=128),
        **hu.gcs
    )
    def test_weighted_sample(self, batch, weights_len, gc, dc):

        weights = np.zeros((batch, weights_len))
        values = np.zeros((batch, weights_len))
        rand_indices = []

            

Reported by Pylint.

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

Line: 43 Column: 9

                      workspace.FeedBlob("values", values.astype(np.float32))

        # output both indices and values
        op = core.CreateOperator(
            "WeightedSample", ["weights", "values"],
            ["sample_indices", "sample_values"]
        )
        workspace.RunOperatorOnce(op)
        result_indices = workspace.FetchBlob("sample_indices")

            

Reported by Pylint.

test/jit/test_modules.py
10 issues
Unable to import 'torch'
Error

Line: 1 Column: 1

              import torch
import os
import sys
from torch.testing._internal.jit_utils import JitTestCase

# Make the helper files in test/ importable
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pytorch_test_dir)


            

Reported by Pylint.

Unable to import 'torch.testing._internal.jit_utils'
Error

Line: 4 Column: 1

              import torch
import os
import sys
from torch.testing._internal.jit_utils import JitTestCase

# Make the helper files in test/ importable
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pytorch_test_dir)


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import torch
import os
import sys
from torch.testing._internal.jit_utils import JitTestCase

# Make the helper files in test/ importable
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pytorch_test_dir)


            

Reported by Pylint.

standard import "import os" should be placed before "import torch"
Error

Line: 2 Column: 1

              import torch
import os
import sys
from torch.testing._internal.jit_utils import JitTestCase

# Make the helper files in test/ importable
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pytorch_test_dir)


            

Reported by Pylint.

standard import "import sys" should be placed before "import torch"
Error

Line: 3 Column: 1

              import torch
import os
import sys
from torch.testing._internal.jit_utils import JitTestCase

# Make the helper files in test/ importable
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.append(pytorch_test_dir)


            

Reported by Pylint.

Missing class docstring
Error

Line: 15 Column: 1

                                     "\tpython test/test_jit.py TESTNAME\n\n"
                       "instead.")

class TestModules(JitTestCase):
    def test_script_module_with_constants_list(self):
        """
        Test that a module that has __constants__ set to something
        that is not a set can be scripted.
        """

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 15 Column: 1

                                     "\tpython test/test_jit.py TESTNAME\n\n"
                       "instead.")

class TestModules(JitTestCase):
    def test_script_module_with_constants_list(self):
        """
        Test that a module that has __constants__ set to something
        that is not a set can be scripted.
        """

            

Reported by Pylint.

Missing class docstring
Error

Line: 24 Column: 9

              
        # torch.nn.Linear has a __constants__ attribute defined
        # and intialized to a list.
        class Net(torch.nn.Linear):
            x: torch.jit.Final[int]

            def __init__(self):
                super().__init__(5, 10)
                self.x = 0

            

Reported by Pylint.

Too few public methods (0/2)
Error

Line: 24 Column: 9

              
        # torch.nn.Linear has a __constants__ attribute defined
        # and intialized to a list.
        class Net(torch.nn.Linear):
            x: torch.jit.Final[int]

            def __init__(self):
                super().__init__(5, 10)
                self.x = 0

            

Reported by Pylint.

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

Line: 29 Column: 17

              
            def __init__(self):
                super().__init__(5, 10)
                self.x = 0

        self.checkModule(Net(), (torch.randn(5),))

            

Reported by Pylint.

test/cpp/c10d/TestUtils.hpp
10 issues
getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 56 Column: 25 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              }

std::string tmppath() {
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }
  else {
    return autoGenerateTmpFilePath();

            

Reported by FlawFinder.

getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 68 Column: 25 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              std::string tmppath() {
  // TMPFILE is for manual test execution during which the user will specify
  // the full temp file path using the environmental variable TMPFILE
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }

  const char* tmpdir = getenv("TMPDIR");

            

Reported by FlawFinder.

getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 73 Column: 24 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

                  return std::string(tmpfile);
  }

  const char* tmpdir = getenv("TMPDIR");
  if (tmpdir == nullptr) {
    tmpdir = "/tmp";
  }

  // Create template

            

Reported by FlawFinder.

getenv - Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once
Security

Line: 94 Column: 17 CWE codes: 807 20
Suggestion: Check environment variables carefully before using them

              #endif

bool isTSANEnabled() {
  auto s = std::getenv("PYTORCH_TEST_WITH_TSAN");
  return s && strcmp(s, "1") == 0;
}
struct TemporaryFile {
  std::string path;


            

Reported by FlawFinder.

char - Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues
Security

Line: 45 Column: 3 CWE codes: 119 120
Suggestion: Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length

              
#ifdef _WIN32
std::string autoGenerateTmpFilePath() {
  char tmp[L_tmpnam_s];
  errno_t err;
  err = tmpnam_s(tmp, L_tmpnam_s);
  if (err != 0)
  {
    throw std::system_error(errno, std::system_category());

            

Reported by FlawFinder.

tmpfile - Function tmpfile() has a security flaw on some systems (e.g., older System V systems)
Security

Line: 57 Column: 7 CWE codes: 377

              
std::string tmppath() {
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }
  else {
    return autoGenerateTmpFilePath();
  }

            

Reported by FlawFinder.

tmpfile - Function tmpfile() has a security flaw on some systems (e.g., older System V systems)
Security

Line: 58 Column: 24 CWE codes: 377

              std::string tmppath() {
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }
  else {
    return autoGenerateTmpFilePath();
  }
}

            

Reported by FlawFinder.

tmpfile - Function tmpfile() has a security flaw on some systems (e.g., older System V systems)
Security

Line: 69 Column: 7 CWE codes: 377

                // TMPFILE is for manual test execution during which the user will specify
  // the full temp file path using the environmental variable TMPFILE
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }

  const char* tmpdir = getenv("TMPDIR");
  if (tmpdir == nullptr) {

            

Reported by FlawFinder.

tmpfile - Function tmpfile() has a security flaw on some systems (e.g., older System V systems)
Security

Line: 70 Column: 24 CWE codes: 377

                // the full temp file path using the environmental variable TMPFILE
  const char* tmpfile = getenv("TMPFILE");
  if (tmpfile) {
    return std::string(tmpfile);
  }

  const char* tmpdir = getenv("TMPDIR");
  if (tmpdir == nullptr) {
    tmpdir = "/tmp";

            

Reported by FlawFinder.

mkstemp - Potential for temporary file vulnerability in some circumstances. Some older Unix-like systems create temp files with permission to write by all by default, so be sure to set the umask to override this. Also, some older Unix systems might fail to use O_EXCL when opening the file, so make sure that O_EXCL is used by the library
Security

Line: 84 Column: 13 CWE codes: 377

                tmp.resize(len);

  // Create temporary file
  auto fd = mkstemp(&tmp[0]);
  if (fd == -1) {
    throw std::system_error(errno, std::system_category());
  }
  close(fd);
  return std::string(tmp.data(), tmp.size());

            

Reported by FlawFinder.