Skip to content

Commit

Permalink
Typing part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus committed Jul 26, 2022
1 parent a214b62 commit df589bf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ inline-quotes = double
enable-extensions = TC, TC1
type-checking-exempt-modules = typing, typing-extensions
eradicate-whitelist-extend = ^-.*;
extend-ignore =
# E203: Whitespace before ':'
E203
per-file-ignores =
__init__.py:F401
exclude =
Expand Down
4 changes: 3 additions & 1 deletion crashtest/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ 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: object) -> bool:
if not isinstance(other, Frame):
raise NotImplementedError
return (
self._filename == other.filename
and self._function == other.function
Expand Down
4 changes: 3 additions & 1 deletion crashtest/frame_collection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import Any


if TYPE_CHECKING:

from crashtest.frame import Frame


class FrameCollection(list):
class FrameCollection(list[Any]):
def __init__(self, frames: list[Frame] | None = None, count: int = 0) -> None:
if frames is None:
frames = []
Expand Down
10 changes: 5 additions & 5 deletions tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from __future__ import annotations


def simple_exception():
def simple_exception() -> None:
raise ValueError("Simple Exception")


def nested_exception():
def nested_exception() -> None:
try:
simple_exception()
except ValueError:
raise RuntimeError("Nested Exception")


def recursive_exception():
def inner():
def recursive_exception() -> None:
def inner() -> None:
outer()

def outer():
def outer() -> None:
inner()

inner()
6 changes: 3 additions & 3 deletions tests/solution_providers/test_solution_provider_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ def documentation_links(self) -> list[str]:
return ["https://foo.bar"]


def test_it_has_no_provider_by_default():
def test_it_has_no_provider_by_default() -> None:
repository = SolutionProviderRepository()

assert len(repository._solution_providers) == 0


def test_providers_can_be_passed_to_constructor():
def test_providers_can_be_passed_to_constructor() -> None:
repository = SolutionProviderRepository()

assert len(repository._solution_providers) == 0


def test_it_can_find_solutions():
def test_it_can_find_solutions() -> None:
repository = SolutionProviderRepository()

repository.register_solution_provider(ExceptionSolutionProvider)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tests.helpers import simple_exception


def test_frame():
def test_frame() -> None:
try:
simple_exception()
except ValueError as e:
Expand Down Expand Up @@ -38,7 +38,7 @@ def test_frame():
assert hash(other_frame) != hash(frame)


def test_frame_with_no_context_should_return_empty_line():
def test_frame_with_no_context_should_return_empty_line() -> None:
frame = Frame(inspect.FrameInfo(None, "filename.py", 123, "function", None, 3))

assert frame.line == ""
6 changes: 3 additions & 3 deletions tests/test_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from tests.helpers import simple_exception


def test_inspector_with_simple_exception():
def test_inspector_with_simple_exception() -> None:
try:
simple_exception()
except ValueError as e:
Expand All @@ -20,7 +20,7 @@ def test_inspector_with_simple_exception():
assert len(inspector.frames) > 0


def test_inspector_with_nested_exception():
def test_inspector_with_nested_exception() -> None:
try:
nested_exception()
except RuntimeError as e:
Expand All @@ -35,7 +35,7 @@ def test_inspector_with_nested_exception():
assert len(inspector.frames.compact()) == 1


def test_inspector_with_recursive_exception():
def test_inspector_with_recursive_exception() -> None:
try:
recursive_exception()
except RuntimeError as e:
Expand Down

0 comments on commit df589bf

Please sign in to comment.