Skip to content

Commit

Permalink
refactor: Remove Python 3.7 related code
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jun 27, 2023
1 parent 5730f5f commit b412f29
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 127 deletions.
8 changes: 1 addition & 7 deletions src/duty/callables/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


def _run(args: list[str]) -> None:
from coverage.cmdline import main as coverage
Expand Down
7 changes: 1 addition & 6 deletions src/duty/callables/flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


@lazy(name="flake8")
def run(
Expand Down
8 changes: 1 addition & 7 deletions src/duty/callables/interrogate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal

_BADGE_STYLE = Literal["flat", "flat-square", "flat-square-modified", "for-the-badge", "plastic", "social"]


Expand Down
8 changes: 1 addition & 7 deletions src/duty/callables/isort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal

Multiline = Literal[
"GRID",
"VERTICAL",
Expand Down
8 changes: 1 addition & 7 deletions src/duty/callables/mypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,12 @@

from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

from duty.callables._io import _LazyStderr, _LazyStdout

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


@lazy(name="mypy")
def run(
Expand Down
8 changes: 1 addition & 7 deletions src/duty/callables/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

from __future__ import annotations

import sys
from typing import Literal

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


@lazy(name="pytest")
def run(
Expand Down
8 changes: 1 addition & 7 deletions src/duty/callables/safety.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
import importlib
import sys
from io import StringIO
from typing import Sequence, cast
from typing import Literal, Sequence, cast

from failprint.lazy import lazy

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from typing_extensions import Literal
else:
from typing import Literal


@lazy(name="safety.check")
def check(
Expand Down
7 changes: 1 addition & 6 deletions src/duty/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@
from __future__ import annotations

import sys
from functools import cached_property
from inspect import Parameter, Signature, signature
from typing import Any, Callable, Sequence

# TODO: remove once support for Python 3.7 is dropped
if sys.version_info < (3, 8):
from cached_property import cached_property
else:
from functools import cached_property


def to_bool(value: str) -> bool:
"""Convert a string to a boolean.
Expand Down
16 changes: 16 additions & 0 deletions tests/fixtures/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,19 @@ def varkw_param(ctx, a: int, **b: int):

def varkw_no_annotation(ctx, **a):
pass # pragma: no cover


def posonly_marker(ctx, a: int, /, b: int):
pass # pragma: no cover


def kwonly_marker(ctx, a: int, *, b: int):
pass # pragma: no cover


def only_markers(ctx, a: int, /, b: int, *, c: int):
pass # pragma: no cover


def full(ctx, a: int, /, b: int, *c: int, d: int, e: int = 0, **f: int):
pass # pragma: no cover
14 changes: 0 additions & 14 deletions tests/fixtures/validation_38.py

This file was deleted.

85 changes: 26 additions & 59 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

from __future__ import annotations

import sys
from inspect import Parameter
from typing import Any, Callable

import pytest

from duty.validation import ParamsCaster, cast_arg, to_bool
from tests.fixtures import validation as validation_fixture

if sys.version_info >= (3, 8, 0):
from tests.fixtures import validation_38 as validation_fixture_38
from tests.fixtures import validation as valfix


@pytest.mark.parametrize(
Expand Down Expand Up @@ -92,62 +88,33 @@ def test_cast_arg(arg: str, annotation: Any, expected: Any) -> None:


_parametrization = [
(validation_fixture.no_params, (), {}, (), {}),
(validation_fixture.pos_or_kw_param, ("1",), {}, (1,), {}),
(validation_fixture.pos_or_kw_param, (), {"a": "1"}, (), {"a": 1}),
(validation_fixture.pos_or_kw_params, ("1", "2"), {}, (1, 2), {}),
(validation_fixture.pos_or_kw_params, ("1",), {"b": "2"}, (1,), {"b": 2}),
(validation_fixture.pos_or_kw_params, (), {"a": "1", "b": "2"}, (), {"a": 1, "b": 2}),
(validation_fixture.varpos_param, (), {}, (), {}),
(validation_fixture.varpos_param, ("1", "2"), {}, (1, 2), {}),
(validation_fixture.pos_and_varpos_param, ("1",), {}, (1,), {}),
(validation_fixture.pos_and_varpos_param, ("1", "2"), {}, (1, 2), {}),
(validation_fixture.pos_and_varpos_param, ("1", "2", "3"), {}, (1, 2, 3), {}),
(validation_fixture.kwonly_param, (), {"b": "1"}, (), {"b": 1}),
(validation_fixture.kwonly_param, ("2",), {"b": "1"}, (2,), {"b": 1}),
(
validation_fixture.kwonly_param,
(
"2",
"3",
),
{"b": "1"},
(2, 3),
{"b": 1},
),
(validation_fixture.varkw_param, ("1",), {}, (1,), {}),
(validation_fixture.varkw_param, ("1",), {"b": "2"}, (1,), {"b": 2}),
(validation_fixture.varkw_param, ("1",), {"b": "2", "c": "3"}, (1,), {"b": 2, "c": 3}),
(validation_fixture.varkw_no_annotation, (), {"a": "1"}, (), {"a": "1"}),
(validation_fixture.no_params, (), {"a": "1"}, (), {"a": "1"}),
(valfix.no_params, (), {}, (), {}),
(valfix.pos_or_kw_param, ("1",), {}, (1,), {}),
(valfix.pos_or_kw_param, (), {"a": "1"}, (), {"a": 1}),
(valfix.pos_or_kw_params, ("1", "2"), {}, (1, 2), {}),
(valfix.pos_or_kw_params, ("1",), {"b": "2"}, (1,), {"b": 2}),
(valfix.pos_or_kw_params, (), {"a": "1", "b": "2"}, (), {"a": 1, "b": 2}),
(valfix.varpos_param, (), {}, (), {}),
(valfix.varpos_param, ("1", "2"), {}, (1, 2), {}),
(valfix.pos_and_varpos_param, ("1",), {}, (1,), {}),
(valfix.pos_and_varpos_param, ("1", "2"), {}, (1, 2), {}),
(valfix.pos_and_varpos_param, ("1", "2", "3"), {}, (1, 2, 3), {}),
(valfix.kwonly_param, (), {"b": "1"}, (), {"b": 1}),
(valfix.kwonly_param, ("2",), {"b": "1"}, (2,), {"b": 1}),
(valfix.kwonly_param, ("2", "3"), {"b": "1"}, (2, 3), {"b": 1}),
(valfix.varkw_param, ("1",), {}, (1,), {}),
(valfix.varkw_param, ("1",), {"b": "2"}, (1,), {"b": 2}),
(valfix.varkw_param, ("1",), {"b": "2", "c": "3"}, (1,), {"b": 2, "c": 3}),
(valfix.varkw_no_annotation, (), {"a": "1"}, (), {"a": "1"}),
(valfix.posonly_marker, ("1", "2"), {}, (1, 2), {}),
(valfix.posonly_marker, ("1",), {"b": "2"}, (1,), {"b": 2}),
(valfix.kwonly_marker, ("1",), {"b": "2"}, (1,), {"b": 2}),
(valfix.kwonly_marker, (), {"a": "1", "b": "2"}, (), {"a": 1, "b": 2}),
(valfix.only_markers, ("1",), {"b": "2", "c": "3"}, (1,), {"b": 2, "c": 3}),
(valfix.only_markers, ("1", "2"), {"c": "3"}, (1, 2), {"c": 3}),
(valfix.full, ("1", "2", "3", "4"), {"d": "5", "e": "6", "f": "7"}, (1, 2, 3, 4), {"d": 5, "e": 6, "f": 7}),
]

if sys.version_info >= (3, 8, 0):
_parametrization.extend(
[
(validation_fixture_38.posonly_marker, ("1", "2"), {}, (1, 2), {}),
(validation_fixture_38.posonly_marker, ("1",), {"b": "2"}, (1,), {"b": 2}),
(validation_fixture_38.kwonly_marker, ("1",), {"b": "2"}, (1,), {"b": 2}),
(validation_fixture_38.kwonly_marker, (), {"a": "1", "b": "2"}, (), {"a": 1, "b": 2}),
(validation_fixture_38.only_markers, ("1",), {"b": "2", "c": "3"}, (1,), {"b": 2, "c": 3}),
(validation_fixture_38.only_markers, ("1", "2"), {"c": "3"}, (1, 2), {"c": 3}),
(
validation_fixture_38.full,
("1", "2", "3", "4"),
{"d": "5", "e": "6", "f": "7"},
(1, 2, 3, 4),
{"d": 5, "e": 6, "f": 7},
),
(
validation_fixture_38.full,
("1", "3", "4"),
{"b": "2", "d": "5"},
(1, 3, 4),
{"b": 2, "d": 5},
),
],
)


@pytest.mark.parametrize(
("func", "args", "kwargs", "expected_args", "expected_kwargs"),
Expand Down

0 comments on commit b412f29

Please sign in to comment.