From ea454df02f6f488f59d1d9b3916d908dfd82703c Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Thu, 18 Jan 2024 14:23:30 -0500 Subject: [PATCH] tox -e lint --- src/ped/__init__.py | 22 +++++++++++++--------- src/ped/guess_module.py | 2 +- src/ped/install_completion.py | 4 ++-- src/ped/pypath.py | 4 ++-- src/ped/style.py | 2 +- tests/test_ped.py | 2 +- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/ped/__init__.py b/src/ped/__init__.py index 290c51b..c4faed0 100755 --- a/src/ped/__init__.py +++ b/src/ped/__init__.py @@ -3,8 +3,6 @@ Example: ped django.core.urlresolvers """ -from types import ModuleType -from typing import Optional, Tuple, Any import argparse import importlib import inspect @@ -12,11 +10,13 @@ import shlex import subprocess import sys +from pathlib import Path +from types import ModuleType +from typing import Any, Optional, Tuple -from .guess_module import guess_module, get_names_by_prefix +from .guess_module import get_names_by_prefix, guess_module from .pypath import patch_sys_path -from .style import print_error, style, sprint, GREEN -from pathlib import Path +from .style import GREEN, print_error, sprint, style __version__ = "2.1.0" @@ -89,13 +89,15 @@ def get_info(ipath: str) -> Tuple[str, str, Optional[int]]: module_name = ipath try: obj = import_object(module_name) - except ImportError: + except ImportError as error: guessed = guess_module(ipath) if guessed: module_name = guessed[0] obj = import_object(module_name) else: - raise ImportError(f'Cannot find any module that matches "{ipath}"') + raise ImportError( + f'Cannot find any module that matches "{ipath}"' + ) from error fpath = find_file(obj) if not fpath: raise ImportError(f'Cannot find any module that matches "{ipath}"') @@ -113,8 +115,10 @@ def import_object(ipath: str) -> ModuleType: mod = importlib.import_module(module_name) try: return getattr(mod, symbol_name) - except AttributeError: - raise ImportError(f'Cannot import "{symbol_name}" from "{module_name}"') + except AttributeError as error: + raise ImportError( + f'Cannot import "{symbol_name}" from "{module_name}"' + ) from error raise err diff --git a/src/ped/guess_module.py b/src/ped/guess_module.py index 6bdf7df..3ab674f 100644 --- a/src/ped/guess_module.py +++ b/src/ped/guess_module.py @@ -3,7 +3,6 @@ Much of this code is adapted from IPython.core.completerlib (see NOTICE for license information). """ -from typing import List, Generator import difflib import inspect import os @@ -12,6 +11,7 @@ import time import zipimport from importlib.machinery import all_suffixes +from typing import Generator, List _suffixes = all_suffixes() diff --git a/src/ped/install_completion.py b/src/ped/install_completion.py index a7c3d23..fc0b179 100644 --- a/src/ped/install_completion.py +++ b/src/ped/install_completion.py @@ -1,7 +1,7 @@ """Script to install bash and zsh completion for ped.""" -from pathlib import Path -import sys import os +import sys +from pathlib import Path from .style import print_error, style diff --git a/src/ped/pypath.py b/src/ped/pypath.py index 2b0b9cc..98abf93 100644 --- a/src/ped/pypath.py +++ b/src/ped/pypath.py @@ -1,7 +1,7 @@ -from typing import List -import sys import shutil import subprocess +import sys +from typing import List def patch_sys_path() -> None: diff --git a/src/ped/style.py b/src/ped/style.py index c299ed2..6ff4bd8 100644 --- a/src/ped/style.py +++ b/src/ped/style.py @@ -1,6 +1,6 @@ -from typing import Optional, IO, Any import os import sys +from typing import IO, Any, Optional RED = 31 GREEN = 32 diff --git a/tests/test_ped.py b/tests/test_ped.py index c0d6fbd..4daaa84 100644 --- a/tests/test_ped.py +++ b/tests/test_ped.py @@ -2,13 +2,13 @@ import email import email.mime from email.mime.message import MIMEMessage +from pathlib import Path import pytest from scripttest import TestFileEnvironment as FileEnvironment import ped from ped.guess_module import guess_module -from pathlib import Path def test_dir_opening(monkeypatch):