Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: update type hints #734

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions troubadix/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import sys
from argparse import ArgumentParser, Namespace
from collections.abc import Sequence
from multiprocessing import cpu_count
from pathlib import Path
from typing import Iterable

from pontos.terminal import Terminal

Expand Down Expand Up @@ -56,7 +56,7 @@ def check_cpu_count(number: str) -> int:

def parse_args(
terminal: Terminal,
args: Iterable[str] = None,
args: Sequence[str],
) -> Namespace:
"""Parsing args for troubadix
Expand Down
16 changes: 8 additions & 8 deletions troubadix/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from abc import ABC, abstractmethod
from collections.abc import Iterable, Iterator
from dataclasses import dataclass
from pathlib import Path
from typing import Iterable, Iterator, Optional
from typing import Optional

from troubadix.helper import CURRENT_ENCODING

Expand Down Expand Up @@ -50,13 +51,13 @@
self,
*,
root: Path,
nasl_file: Path = None,
nasl_file: Path,
) -> None:
self.root = root
self.nasl_file = nasl_file

self._file_content = None
self._lines = None
self._file_content: str | None = None
self._lines: list[str] | None = None

Check warning on line 60 in troubadix/plugin.py

View check run for this annotation

Codecov / codecov/patch

troubadix/plugin.py#L59-L60

Added lines #L59 - L60 were not covered by tests

@property
def file_content(self) -> str:
Expand All @@ -67,7 +68,7 @@
return self._file_content

@property
def lines(self) -> Iterable[str]:
def lines(self) -> list[str]:
if not self._lines:
self._lines = self.file_content.splitlines()
return self._lines
Expand All @@ -82,15 +83,14 @@
class Plugin(ABC):
"""A linter plugin"""

name: str = None
description: str = None
name: str

@abstractmethod
def run(self) -> Iterator[LinterResult]:
pass

def fix(self) -> Iterator[LinterResult]:
return []
return iter([])

Check warning on line 93 in troubadix/plugin.py

View check run for this annotation

Codecov / codecov/patch

troubadix/plugin.py#L93

Added line #L93 was not covered by tests


class FilesPlugin(Plugin):
Expand Down
8 changes: 4 additions & 4 deletions troubadix/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections.abc import Iterable
from pathlib import Path
from typing import Iterable, List

from pontos.terminal import Terminal

Expand All @@ -33,8 +33,8 @@ def __init__(
root: Path,
*,
fix: bool = False,
log_file: Path = None,
log_file_statistic: Path = None,
log_file: Path | None = None,
log_file_statistic: Path | None = None,
statistic: bool = True,
verbose: int = 0,
ignore_warnings: bool = False,
Expand Down Expand Up @@ -78,7 +78,7 @@ def _report_ok(self, message: str) -> None:
self._log_append(f"\t\t{message}".replace("\n", "\n\t\t"))

def _process_plugin_results(
self, plugin_name: str, plugin_results: List[LinterResult]
self, plugin_name: str, plugin_results: Iterable[LinterResult]
):
"""Process the results of a plugin: Print/Log results if
verbosity/logging fits and count the results"""
Expand Down
6 changes: 2 additions & 4 deletions troubadix/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from collections import defaultdict
from collections.abc import Iterator
from pathlib import Path
from typing import Dict, Iterable, Iterator

from troubadix.plugin import LinterResult, LinterWarning


class Results:
def __init__(self, ignore_warnings: bool = False) -> None:
self.plugin_results: Dict[str, Iterable[LinterResult]] = defaultdict(
list
)
self.plugin_results: dict[str, list[LinterResult]] = defaultdict(list)
self.has_plugin_results = False
self._ignore_warnings = ignore_warnings

Expand Down
8 changes: 4 additions & 4 deletions troubadix/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import datetime
import signal
from collections.abc import Iterable
from multiprocessing import Pool
from pathlib import Path
from typing import Iterable

from troubadix.helper.patterns import (
init_script_tag_patterns,
Expand Down Expand Up @@ -49,11 +49,11 @@ def __init__(
reporter: Reporter,
*,
root: Path,
excluded_plugins: Iterable[str] = None,
included_plugins: Iterable[str] = None,
excluded_plugins: Iterable[str] | None = None,
included_plugins: Iterable[str] | None = None,
fix: bool = False,
ignore_warnings: bool = False,
) -> bool:
) -> None:
# plugins initialization
self.plugins = StandardPlugins(excluded_plugins, included_plugins)

Expand Down
12 changes: 6 additions & 6 deletions troubadix/troubadix.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
""" Main module for troubadix """

import sys
from collections.abc import Iterable
from pathlib import Path
from typing import Iterable, List, Tuple

from pontos.terminal import Terminal
from pontos.terminal.terminal import ConsoleTerminal
Expand All @@ -35,7 +35,7 @@ def generate_file_list(
dirs: Iterable[Path],
exclude_patterns: Iterable[str],
include_patterns: Iterable[str],
) -> List[Path]:
) -> list[Path]:
"""Generates a files list under respect of several given arguments
Arguments:
Expand All @@ -48,7 +48,7 @@ def generate_file_list(
Returns
List of Path objects"""
files: List[Path] = []
files: list[Path] = []
for directory in dirs:
for pattern in include_patterns:
files.extend(directory.glob(pattern))
Expand All @@ -64,10 +64,10 @@ def generate_file_list(

def generate_patterns(
terminal: ConsoleTerminal,
include_patterns: List[str],
exclude_patterns: List[str],
include_patterns: list[str],
exclude_patterns: list[str],
non_recursive: bool,
) -> Tuple[List[str], List[str]]:
) -> tuple[list[str], list[str]]:
"""Generates the include and exclude patterns
Arguments:
Expand Down
Loading