Skip to content

Commit

Permalink
Change: update type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHargarter committed Aug 9, 2024
1 parent 318f02a commit 4fc10f2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
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 @@ def __init__(
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

@property
def file_content(self) -> str:
Expand All @@ -67,7 +68,7 @@ def file_content(self) -> str:
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 @@ def __init__(self, *, root: Path, nasl_files: Iterable[Path]) -> None:
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([])


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

0 comments on commit 4fc10f2

Please sign in to comment.