The following issues were found

tools/build_libtorch.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              import argparse
from os.path import dirname, abspath
import sys

# By appending pytorch_root to sys.path, this module can import other torch
# modules even when run as a standalone script. i.e., it's okay either you
# do `python build_libtorch.py` or `python -m tools.build_libtorch`.
pytorch_root = dirname(dirname(abspath(__file__)))
sys.path.append(pytorch_root)

            

Reported by Pylint.

Import "from tools.build_pytorch_libs import build_caffe2" should be placed at the top of the module
Error

Line: 11 Column: 1

              pytorch_root = dirname(dirname(abspath(__file__)))
sys.path.append(pytorch_root)

from tools.build_pytorch_libs import build_caffe2
from tools.setup_helpers.cmake import CMake

if __name__ == '__main__':
    # Placeholder for future interface. For now just gives a nice -h.
    parser = argparse.ArgumentParser(description='Build libtorch')

            

Reported by Pylint.

Import "from tools.setup_helpers.cmake import CMake" should be placed at the top of the module
Error

Line: 12 Column: 1

              sys.path.append(pytorch_root)

from tools.build_pytorch_libs import build_caffe2
from tools.setup_helpers.cmake import CMake

if __name__ == '__main__':
    # Placeholder for future interface. For now just gives a nice -h.
    parser = argparse.ArgumentParser(description='Build libtorch')
    options = parser.parse_args()

            

Reported by Pylint.

tools/linter/install/clang_tidy.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              import os
from tools.linter.install.download_bin import download, PYTORCH_ROOT, HASH_PATH

PLATFORM_TO_URL = {
    "Linux": "https://oss-clang-format.s3.us-east-2.amazonaws.com/linux64/clang-tidy",
    "Darwin": "https://oss-clang-format.s3.us-east-2.amazonaws.com/macos/clang-tidy",
}

PLATFORM_TO_HASH = {

            

Reported by Pylint.

Constant name "ok" doesn't conform to UPPER_CASE naming style
Error

Line: 18 Column: 5

              INSTALLATION_PATH = os.path.join(OUTPUT_DIR, "clang-tidy")

if __name__ == "__main__":
    ok = download("clang-tidy", OUTPUT_DIR, PLATFORM_TO_URL, PLATFORM_TO_HASH)
    if not ok:
        print("Installation failed!")
        exit(1)

            

Reported by Pylint.

Consider using sys.exit()
Error

Line: 21 Column: 9

                  ok = download("clang-tidy", OUTPUT_DIR, PLATFORM_TO_URL, PLATFORM_TO_HASH)
    if not ok:
        print("Installation failed!")
        exit(1)

            

Reported by Pylint.

tools/linter/mypy_wrapper.py
3 issues
Unable to import 'mypy.api'
Error

Line: 27 Column: 1

              from pathlib import Path, PurePath, PurePosixPath
from typing import Any, Dict, List, Optional, Set, Tuple

import mypy.api
# not part of the public API, but this is the easiest way to ensure that
# we agree with what mypy actually does
import mypy.config_parser



            

Reported by Pylint.

Unable to import 'mypy.config_parser'
Error

Line: 30 Column: 1

              import mypy.api
# not part of the public API, but this is the easiest way to ensure that
# we agree with what mypy actually does
import mypy.config_parser


def read_config(config_path: Path) -> Set[str]:
    """
    Return the set of `files` in the `mypy` ini file at config_path.

            

Reported by Pylint.

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

Line: 84 Column: 13

                  """
    trie: Trie = {}
    for ini, files in configs.items():
        for f in files:
            inner = trie
            for segment in split_path(f):
                inner = inner.setdefault(segment, {})
            inner.setdefault(None, set()).add(ini)
    return trie

            

Reported by Pylint.

third_party/miniz-2.0.8/examples/example5.c
3 issues
atoi - Unless checked, the resulting number can exceed the expected range
Security

Line: 82 Column: 21 CWE codes: 190
Suggestion: If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)

                    {
         case 'l':
         {
            level = atoi(&argv[1][2]);
            if ((level < 0) || (level > 10))
            {
               printf("Invalid level!\n");
               return EXIT_FAILURE;
            }

            

Reported by FlawFinder.

fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 123 Column: 14 CWE codes: 362

                 printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);

   // Open input file.
   pInfile = fopen(pSrc_filename, "rb");
   if (!pInfile)
   {
      printf("Failed opening input file!\n");
      return EXIT_FAILURE;
   }

            

Reported by FlawFinder.

fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 145 Column: 15 CWE codes: 362

                 infile_size = (uint)file_loc;

   // Open output file.
   pOutfile = fopen(pDst_filename, "wb");
   if (!pOutfile)
   {
      printf("Failed opening output file!\n");
      return EXIT_FAILURE;
   }

            

Reported by FlawFinder.

tools/setup_helpers/__init__.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              import os
import sys
from typing import Optional


def which(thefile: str) -> Optional[str]:
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    for d in path:
        fname = os.path.join(d, thefile)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              from typing import Optional


def which(thefile: str) -> Optional[str]:
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    for d in path:
        fname = os.path.join(d, thefile)
        fnames = [fname]
        if sys.platform == 'win32':

            

Reported by Pylint.

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

Line: 8 Column: 9

              
def which(thefile: str) -> Optional[str]:
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    for d in path:
        fname = os.path.join(d, thefile)
        fnames = [fname]
        if sys.platform == 'win32':
            exts = os.environ.get('PATHEXT', '').split(os.pathsep)
            fnames += [fname + ext for ext in exts]

            

Reported by Pylint.

third_party/miniz-2.0.8/examples/example3.c
3 issues
atoi - Unless checked, the resulting number can exceed the expected range
Security

Line: 50 Column: 17 CWE codes: 190
Suggestion: If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended)

                  {
      case 'l':
      {
        level = atoi(&argv[1][2]);
        if ((level < 0) || (level > 10))
        {
          printf("Invalid level!\n");
          return EXIT_FAILURE;
        }

            

Reported by FlawFinder.

fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 91 Column: 13 CWE codes: 362

                printf("Mode: %c, Level: %u\nInput File: \"%s\"\nOutput File: \"%s\"\n", pMode[0], level, pSrc_filename, pDst_filename);

  // Open input file.
  pInfile = fopen(pSrc_filename, "rb");
  if (!pInfile)
  {
    printf("Failed opening input file!\n");
    return EXIT_FAILURE;
  }

            

Reported by FlawFinder.

fopen - Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents?
Security

Line: 113 Column: 14 CWE codes: 362

                infile_size = (uint)file_loc;

  // Open output file.
  pOutfile = fopen(pDst_filename, "wb");
  if (!pOutfile)
  {
    printf("Failed opening output file!\n");
    return EXIT_FAILURE;
  }

            

Reported by FlawFinder.

tools/setup_helpers/numpy_.py
3 issues
Attempted relative import beyond top-level package
Error

Line: 8 Column: 1

              nature.
"""

from .env import check_negative_env_flag


# Set USE_NUMPY to what the user wants, because even if we fail here, cmake
# will check for the presence of NumPy again (`cmake/Dependencies.cmake`).
USE_NUMPY = not check_negative_env_flag('USE_NUMPY')

            

Reported by Pylint.

Line too long (118/100)
Error

Line: 3 Column: 1

              """NumPy helper.

Note: If you plan to add a library detection script like this one, consider it twice. Most library detection should go
to CMake script. This one is an exception, because Python code can do a much better job due to NumPy's inherent Pythonic
nature.
"""

from .env import check_negative_env_flag


            

Reported by Pylint.

Line too long (120/100)
Error

Line: 4 Column: 1

              """NumPy helper.

Note: If you plan to add a library detection script like this one, consider it twice. Most library detection should go
to CMake script. This one is an exception, because Python code can do a much better job due to NumPy's inherent Pythonic
nature.
"""

from .env import check_negative_env_flag


            

Reported by Pylint.

tools/shared/__init__.py
3 issues
Unable to import '__init__.module_loader'
Error

Line: 1 Column: 1

              from .module_loader import import_module
from .cwrap_common import set_declaration_defaults, sort_by_number_of_args

            

Reported by Pylint.

Unable to import '__init__.cwrap_common'
Error

Line: 2 Column: 1

              from .module_loader import import_module
from .cwrap_common import set_declaration_defaults, sort_by_number_of_args

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from .module_loader import import_module
from .cwrap_common import set_declaration_defaults, sort_by_number_of_args

            

Reported by Pylint.

tools/shared/module_loader.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              from importlib.abc import Loader
from types import ModuleType
from typing import cast


def import_module(name: str, path: str) -> ModuleType:
    import importlib.util
    spec = importlib.util.spec_from_file_location(name, path)
    module = importlib.util.module_from_spec(spec)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              from typing import cast


def import_module(name: str, path: str) -> ModuleType:
    import importlib.util
    spec = importlib.util.spec_from_file_location(name, path)
    module = importlib.util.module_from_spec(spec)
    cast(Loader, spec.loader).exec_module(module)
    return module

            

Reported by Pylint.

Import outside toplevel (importlib.util)
Error

Line: 7 Column: 5

              

def import_module(name: str, path: str) -> ModuleType:
    import importlib.util
    spec = importlib.util.spec_from_file_location(name, path)
    module = importlib.util.module_from_spec(spec)
    cast(Loader, spec.loader).exec_module(module)
    return module

            

Reported by Pylint.

test/typing/fail/random.py
3 issues
Unable to import 'torch'
Error

Line: 2 Column: 1

              # flake8: noqa
import torch

torch.set_rng_state([1, 2, 3])  # E: Argument 1 to "set_rng_state" has incompatible type "List[int]"; expected "Tensor"

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # flake8: noqa
import torch

torch.set_rng_state([1, 2, 3])  # E: Argument 1 to "set_rng_state" has incompatible type "List[int]"; expected "Tensor"

            

Reported by Pylint.

Line too long (119/100)
Error

Line: 4 Column: 1

              # flake8: noqa
import torch

torch.set_rng_state([1, 2, 3])  # E: Argument 1 to "set_rng_state" has incompatible type "List[int]"; expected "Tensor"

            

Reported by Pylint.