The following issues were found

Tools/scripts/crlf.py
4 issues
Multiple imports on one line (sys, os)
Error

Line: 4 Column: 1

              #! /usr/bin/env python3
"Replace CRLF with LF in argument files.  Print names of changed files."

import sys, os

def main():
    for filename in sys.argv[1:]:
        if os.path.isdir(filename):
            print(filename, "Directory!")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              
import sys, os

def main():
    for filename in sys.argv[1:]:
        if os.path.isdir(filename):
            print(filename, "Directory!")
            continue
        with open(filename, "rb") as f:

            

Reported by Pylint.

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

Line: 11 Column: 38

                      if os.path.isdir(filename):
            print(filename, "Directory!")
            continue
        with open(filename, "rb") as f:
            data = f.read()
        if b'\0' in data:
            print(filename, "Binary!")
            continue
        newdata = data.replace(b"\r\n", b"\n")

            

Reported by Pylint.

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

Line: 19 Column: 42

                      newdata = data.replace(b"\r\n", b"\n")
        if newdata != data:
            print(filename)
            with open(filename, "wb") as f:
                f.write(newdata)

if __name__ == '__main__':
    main()

            

Reported by Pylint.

Tools/scripts/reindent-rst.py
4 issues
Dangerous default value sys.argv (builtins.list) as argument
Error

Line: 10 Column: 1

              
import patchcheck

def main(argv=sys.argv):
    patchcheck.normalize_docs_whitespace(argv[1:])

if __name__ == '__main__':
    sys.exit(main())

            

Reported by Pylint.

Module name "reindent-rst" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

# Make a reST file compliant to our pre-commit hook.
# Currently just remove trailing whitespace.

import sys

import patchcheck


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

# Make a reST file compliant to our pre-commit hook.
# Currently just remove trailing whitespace.

import sys

import patchcheck


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              
import patchcheck

def main(argv=sys.argv):
    patchcheck.normalize_docs_whitespace(argv[1:])

if __name__ == '__main__':
    sys.exit(main())

            

Reported by Pylint.

Tools/scripts/findlinksto.py
4 issues
Unused variable 'opts'
Error

Line: 14 Column: 9

              
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], '')
        if len(args) < 2:
            raise getopt.GetoptError('not enough arguments', None)
    except getopt.GetoptError as msg:
        sys.stdout = sys.stderr
        print(msg)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #! /usr/bin/env python3

# findlinksto
#
# find symbolic links to a path matching a regular expression

import os
import sys
import re

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              import re
import getopt

def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], '')
        if len(args) < 2:
            raise getopt.GetoptError('not enough arguments', None)
    except getopt.GetoptError as msg:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 27 Column: 1

                  for dirname in dirs:
        os.walk(dirname, visit, prog)

def visit(prog, dirname, names):
    if os.path.islink(dirname):
        names[:] = []
        return
    if os.path.ismount(dirname):
        print('descend into', dirname)

            

Reported by Pylint.

Tools/scripts/checkpip.py
3 issues
Access to a protected member _PROJECTS of a client class
Error

Line: 15 Column: 29

              def main():
    outofdate = False

    for project, version in ensurepip._PROJECTS:
        data = json.loads(urllib.request.urlopen(
            "https://pypi.org/pypi/{}/json".format(project),
            cadefault=True,
        ).read().decode("utf8"))
        upstream_version = data["info"]["version"]

            

Reported by Pylint.

Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.
Security blacklist

Line: 16
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b310-urllib-urlopen

                  outofdate = False

    for project, version in ensurepip._PROJECTS:
        data = json.loads(urllib.request.urlopen(
            "https://pypi.org/pypi/{}/json".format(project),
            cadefault=True,
        ).read().decode("utf8"))
        upstream_version = data["info"]["version"]


            

Reported by Bandit.

Missing function or method docstring
Error

Line: 12 Column: 1

              import sys


def main():
    outofdate = False

    for project, version in ensurepip._PROJECTS:
        data = json.loads(urllib.request.urlopen(
            "https://pypi.org/pypi/{}/json".format(project),

            

Reported by Pylint.

Tools/scripts/update_file.py
3 issues
Missing function or method docstring
Error

Line: 13 Column: 1

              import sys


def main(old_path, new_path):
    with open(old_path, 'rb') as f:
        old_contents = f.read()
    with open(new_path, 'rb') as f:
        new_contents = f.read()
    if old_contents != new_contents:

            

Reported by Pylint.

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

Line: 14 Column: 34

              

def main(old_path, new_path):
    with open(old_path, 'rb') as f:
        old_contents = f.read()
    with open(new_path, 'rb') as f:
        new_contents = f.read()
    if old_contents != new_contents:
        os.replace(new_path, old_path)

            

Reported by Pylint.

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

Line: 16 Column: 34

              def main(old_path, new_path):
    with open(old_path, 'rb') as f:
        old_contents = f.read()
    with open(new_path, 'rb') as f:
        new_contents = f.read()
    if old_contents != new_contents:
        os.replace(new_path, old_path)
    else:
        os.unlink(new_path)

            

Reported by Pylint.

Tools/scripts/summarize_specialization_stats.py
3 issues
Probable insecure usage of temp file/directory.
Security

Line: 11
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html

              if os.name == "nt":
    DEFAULT_DIR = "c:\\temp\\py_stats\\"
else:
    DEFAULT_DIR = "/tmp/py_stats/"


TOTAL = "deferred", "hit", "miss", "unquickened"

def print_stats(name, family_stats):

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 16 Column: 1

              
TOTAL = "deferred", "hit", "miss", "unquickened"

def print_stats(name, family_stats):
    total = sum(family_stats[kind] for kind in TOTAL)
    if total == 0:
        return
    print(name+":")
    for key in sorted(family_stats):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 39 Column: 1

                          continue
        print(f"    kind {index:>2}: {value:>8} {100*value/total_failures:0.1f}%")

def main():
    stats = collections.defaultdict(collections.Counter)
    for filename in os.listdir(DEFAULT_DIR):
        for line in open(os.path.join(DEFAULT_DIR, filename)):
            key, value = line.split(":")
            key = key.strip()

            

Reported by Pylint.

Tools/scripts/win_add2path.py
3 issues
Unable to import 'winreg'
Error

Line: 13 Column: 1

              import sys
import site
import os
import winreg

HKCU = winreg.HKEY_CURRENT_USER
ENV = "Environment"
PATH = "PATH"
DEFAULT = "%PATH%"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

              PATH = "PATH"
DEFAULT = "%PATH%"

def modify():
    pythonpath = os.path.dirname(os.path.normpath(sys.executable))
    scripts = os.path.join(pythonpath, "Scripts")
    appdata = os.environ["APPDATA"]
    if hasattr(site, "USER_SITE"):
        usersite = site.USER_SITE.replace(appdata, "%APPDATA%")

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 1

                      winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
        return paths, envpath

def main():
    paths, envpath = modify()
    if len(paths) > 1:
        print("Path(s) added:")
        print('\n'.join(paths[1:]))
    else:

            

Reported by Pylint.

Tools/scripts/find-uname.py
3 issues
Module name "find-uname" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

"""
For each argument on the command line, look for it in the set of all Unicode
names.  Arguments are treated as case-insensitive regular expressions, e.g.:

    % find-uname 'small letter a$' 'horizontal line'
    *** small letter a$ matches ***
    LATIN SMALL LETTER A (97)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

              import sys
import re

def main(args):
    unicode_names = []
    for ix in range(sys.maxunicode+1):
        try:
            unicode_names.append((ix, unicodedata.name(chr(ix))))
        except ValueError: # no name for the character

            

Reported by Pylint.

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

Line: 25 Column: 9

              
def main(args):
    unicode_names = []
    for ix in range(sys.maxunicode+1):
        try:
            unicode_names.append((ix, unicodedata.name(chr(ix))))
        except ValueError: # no name for the character
            pass
    for arg in args:

            

Reported by Pylint.

Lib/unittest/__main__.py
3 issues
Attempted relative import beyond top-level package
Error

Line: 16 Column: 1

              
__unittest = True

from .main import main

main(module=None)

            

Reported by Pylint.

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

Line: 14 Column: 1

                  sys.argv[0] = executable + " -m unittest"
    del os

__unittest = True

from .main import main

main(module=None)

            

Reported by Pylint.

Import "from .main import main" should be placed at the top of the module
Error

Line: 16 Column: 1

              
__unittest = True

from .main import main

main(module=None)

            

Reported by Pylint.

Lib/test/test_warnings/data/stacklevel.py
3 issues
Missing module docstring
Error

Line: 1 Column: 1

              # Helper module for testing the skipmodules argument of warnings.warn()

import warnings

def outer(message, stacklevel=1):
    inner(message, stacklevel)

def inner(message, stacklevel=1):
    warnings.warn(message, stacklevel=stacklevel)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 5 Column: 1

              
import warnings

def outer(message, stacklevel=1):
    inner(message, stacklevel)

def inner(message, stacklevel=1):
    warnings.warn(message, stacklevel=stacklevel)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              def outer(message, stacklevel=1):
    inner(message, stacklevel)

def inner(message, stacklevel=1):
    warnings.warn(message, stacklevel=stacklevel)

            

Reported by Pylint.