Skip to content

Commit

Permalink
Isort, pyupgrade and black
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Jul 26, 2022
1 parent 65f52ba commit e0784b5
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 36 deletions.
3 changes: 3 additions & 0 deletions crashtest/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
from __future__ import annotations


__version__ = "0.3.1"
4 changes: 2 additions & 2 deletions crashtest/contracts/base_solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from .solution import Solution

Expand All @@ -18,5 +18,5 @@ def solution_description(self) -> str:
return self._description

@property
def documentation_links(self) -> List[str]:
def documentation_links(self) -> list[str]:
return self._links
4 changes: 2 additions & 2 deletions crashtest/contracts/has_solutions_for_exception.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from .solution import Solution

Expand All @@ -7,5 +7,5 @@ class HasSolutionsForException:
def can_solve(self, exception: Exception) -> bool:
raise NotImplementedError()

def get_solutions(self, exception: Exception) -> List[Solution]:
def get_solutions(self, exception: Exception) -> list[Solution]:
raise NotImplementedError()
2 changes: 2 additions & 0 deletions crashtest/contracts/provides_solution.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .solution import Solution


Expand Down
4 changes: 2 additions & 2 deletions crashtest/contracts/solution.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations


class Solution:
Expand All @@ -11,5 +11,5 @@ def solution_description(self) -> str:
raise NotImplementedError()

@property
def documentation_links(self) -> List[str]:
def documentation_links(self) -> list[str]:
raise NotImplementedError()
13 changes: 6 additions & 7 deletions crashtest/contracts/solution_provider_repository.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
from typing import List
from typing import Type
from __future__ import annotations

from .solution import Solution


class SolutionProviderRepository:
def register_solution_provider(
self, solution_provider_class: Type
) -> "SolutionProviderRepository":
self, solution_provider_class: type
) -> SolutionProviderRepository:
raise NotImplementedError()

def register_solution_providers(
self, solution_provider_classes: List[Type]
) -> "SolutionProviderRepository":
self, solution_provider_classes: list[type]
) -> SolutionProviderRepository:
raise NotImplementedError()

def get_solutions_for_exception(self, exception: Exception) -> List[Solution]:
def get_solutions_for_exception(self, exception: Exception) -> list[Solution]:
raise NotImplementedError()
7 changes: 4 additions & 3 deletions crashtest/frame.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import inspect

from types import FrameType
from typing import Dict


class Frame:
_content_cache: Dict[str, str] = {}
_content_cache: dict[str, str] = {}

def __init__(self, frame_info: inspect.FrameInfo) -> None:
self._frame = frame_info.frame
Expand Down Expand Up @@ -63,7 +64,7 @@ def file_content(self) -> str:
def __hash__(self) -> int:
return hash(self._filename) ^ hash(self._function) ^ hash(self._lineno)

def __eq__(self, other: "Frame") -> bool:
def __eq__(self, other: Frame) -> bool:
return (
self._filename == other.filename
and self._function == other.function
Expand Down
9 changes: 4 additions & 5 deletions crashtest/frame_collection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import List
from typing import Optional
from __future__ import annotations

from .frame import Frame


class FrameCollection(list):
def __init__(self, frames: Optional[List[Frame]] = None, count: int = 0) -> None:
def __init__(self, frames: list[Frame] | None = None, count: int = 0) -> None:
if frames is None:
frames = []

Expand All @@ -20,12 +19,12 @@ def repetitions(self) -> int:
def is_repeated(self) -> bool:
return self._count > 1

def increment_count(self, increment: int = 1) -> "FrameCollection":
def increment_count(self, increment: int = 1) -> FrameCollection:
self._count += increment

return self

def compact(self) -> List["FrameCollection"]:
def compact(self) -> list[FrameCollection]:
"""
Compacts the frames to deduplicate recursive calls.
"""
Expand Down
6 changes: 3 additions & 3 deletions crashtest/inspector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import inspect
from __future__ import annotations

from typing import Optional
import inspect

from .frame import Frame
from .frame_collection import FrameCollection
Expand Down Expand Up @@ -43,7 +43,7 @@ def frames(self) -> FrameCollection:
return self._frames

@property
def previous_exception(self) -> Optional[Exception]:
def previous_exception(self) -> Exception | None:
return self._previous_exception

def has_previous_exception(self) -> bool:
Expand Down
16 changes: 7 additions & 9 deletions crashtest/solution_providers/solution_provider_repository.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from typing import List
from typing import Optional
from typing import Type
from __future__ import annotations

from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException
from crashtest.contracts.provides_solution import ProvidesSolution
Expand All @@ -11,7 +9,7 @@


class SolutionProviderRepository(BaseSolutionProviderRepository):
def __init__(self, solution_providers: Optional[List[Type]] = None) -> None:
def __init__(self, solution_providers: list[type] | None = None) -> None:
self._solution_providers = []

if solution_providers is None:
Expand All @@ -20,21 +18,21 @@ def __init__(self, solution_providers: Optional[List[Type]] = None) -> None:
self.register_solution_providers(solution_providers)

def register_solution_provider(
self, solution_provider_class: Type
) -> "SolutionProviderRepository":
self, solution_provider_class: type
) -> SolutionProviderRepository:
self._solution_providers.append(solution_provider_class)

return self

def register_solution_providers(
self, solution_provider_classes: List[Type]
) -> "SolutionProviderRepository":
self, solution_provider_classes: list[type]
) -> SolutionProviderRepository:
for solution_provider_class in solution_provider_classes:
self.register_solution_provider(solution_provider_class)

return self

def get_solutions_for_exception(self, exception: Exception) -> List[Solution]:
def get_solutions_for_exception(self, exception: Exception) -> list[Solution]:
solutions = []

if isinstance(exception, Solution):
Expand Down
3 changes: 3 additions & 0 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations


def simple_exception():
raise ValueError("Simple Exception")

Expand Down
6 changes: 3 additions & 3 deletions tests/solution_providers/test_solution_provider_repository.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from __future__ import annotations

from crashtest.contracts.base_solution import BaseSolution
from crashtest.contracts.has_solutions_for_exception import HasSolutionsForException
Expand All @@ -13,7 +13,7 @@ class ExceptionSolutionProvider(HasSolutionsForException):
def can_solve(self, exception: Exception) -> bool:
return isinstance(exception, ExceptionProvidingException)

def get_solutions(self, exception: Exception) -> List[Solution]:
def get_solutions(self, exception: Exception) -> list[Solution]:
return [
BaseSolution("An exception solution", "An exception solution description")
]
Expand All @@ -38,7 +38,7 @@ def solution_description(self) -> str:
return "A solution description"

@property
def documentation_links(self) -> List[str]:
def documentation_links(self) -> list[str]:
return ["https://foo.bar"]


Expand Down
2 changes: 2 additions & 0 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import inspect

from crashtest.frame import Frame
Expand Down
2 changes: 2 additions & 0 deletions tests/test_inspector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from crashtest.inspector import Inspector

from .helpers import nested_exception
Expand Down

0 comments on commit e0784b5

Please sign in to comment.