From 380acbbdf1407f093682ea15b151126dde1666ce Mon Sep 17 00:00:00 2001 From: Andrey Kislyuk Date: Sun, 4 Aug 2024 15:42:06 -0700 Subject: [PATCH] Fix new mypy errors --- .../activate_global_python_argcomplete.py | 3 ++- ...n_argcomplete_check_easy_install_script.py | 24 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/argcomplete/scripts/activate_global_python_argcomplete.py b/argcomplete/scripts/activate_global_python_argcomplete.py index 01142fe..736d603 100755 --- a/argcomplete/scripts/activate_global_python_argcomplete.py +++ b/argcomplete/scripts/activate_global_python_argcomplete.py @@ -91,6 +91,7 @@ def install_to_destination(dest): def get_consent(): + assert args is not None if args.yes is True: return True while True: @@ -140,7 +141,7 @@ def main(): if args.dest != "-" and not os.path.exists(args.dest): parser.error(f"directory {args.dest} was specified via --dest, but it does not exist") destinations.append(args.dest) - elif site.ENABLE_USER_SITE and site.USER_SITE in argcomplete.__file__: + elif site.ENABLE_USER_SITE and site.USER_SITE and site.USER_SITE in argcomplete.__file__: print( "Argcomplete was installed in the user site local directory. Defaulting to user installation.", file=sys.stderr ) diff --git a/argcomplete/scripts/python_argcomplete_check_easy_install_script.py b/argcomplete/scripts/python_argcomplete_check_easy_install_script.py index b74a745..8d64eac 100755 --- a/argcomplete/scripts/python_argcomplete_check_easy_install_script.py +++ b/argcomplete/scripts/python_argcomplete_check_easy_install_script.py @@ -34,33 +34,43 @@ def main(): if line.startswith("# EASY-INSTALL-SCRIPT"): import pkg_resources - dist, script = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line).groups() + re_match = re.match("# EASY-INSTALL-SCRIPT: '(.+)','(.+)'", line) + assert re_match is not None + dist, script = re_match.groups() if "PYTHON_ARGCOMPLETE_OK" in pkg_resources.get_distribution(dist).get_metadata("scripts/" + script): return 0 elif line.startswith("# EASY-INSTALL-ENTRY-SCRIPT"): - dist, group, name = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line).groups() + re_match = re.match("# EASY-INSTALL-ENTRY-SCRIPT: '(.+)','(.+)','(.+)'", line) + assert re_match is not None + dist, group, name = re_match.groups() import pkgutil import pkg_resources - module_name = pkg_resources.get_distribution(dist).get_entry_info(group, name).module_name - with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh: + entry_point_info = pkg_resources.get_distribution(dist).get_entry_info(group, name) + assert entry_point_info is not None + module_name = entry_point_info.module_name + with open(pkgutil.get_loader(module_name).get_filename()) as mod_fh: # type: ignore if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024): return 0 elif line.startswith("# EASY-INSTALL-DEV-SCRIPT"): for line2 in lines: if line2.startswith("__file__"): - filename = re.match("__file__ = '(.+)'", line2).group(1) + re_match = re.match("__file__ = '(.+)'", line2) + assert re_match is not None + filename = re_match.group(1) with open(filename) as mod_fh: if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024): return 0 elif line.startswith("# PBR Generated"): - module = re.search("from (.*) import", head).groups()[0] + re_match = re.search("from (.*) import", head) + assert re_match is not None + module = re_match.groups()[0] import pkgutil import pkg_resources - with open(pkgutil.get_loader(module).get_filename()) as mod_fh: + with open(pkgutil.get_loader(module).get_filename()) as mod_fh: # type: ignore if "PYTHON_ARGCOMPLETE_OK" in mod_fh.read(1024): return 0