Skip to content

Commit

Permalink
chore: Reformat with upgraded linters
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Sep 21, 2024
1 parent ae07b53 commit d9f5907
Show file tree
Hide file tree
Showing 24 changed files with 131 additions and 245 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ from phantom import Phantom
from phantom.predicates.collection import contained


class Name(str, Phantom, predicate=contained({"Jane", "Joe"})):
...
class Name(str, Phantom, predicate=contained({"Jane", "Joe"})): ...


def greet(name: Name):
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath("../src"))

import phantom # noqa: E402
import phantom

current_dir = pathlib.Path(__file__).resolve().parent

Expand Down
4 changes: 2 additions & 2 deletions src/phantom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def is_big(value: int) -> bool:
return value > 5
class Big(int, Phantom, predicate=is_big):
...
class Big(int, Phantom, predicate=is_big): ...
assert isinstance(10, Big) # this passes
"""

from ._base import Phantom
from ._base import PhantomBase
from ._base import PhantomMeta
Expand Down
12 changes: 4 additions & 8 deletions src/phantom/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@

@runtime_checkable
class InstanceCheckable(Protocol):
def __instancecheck__(self, instance: object) -> bool:
...
def __instancecheck__(self, instance: object) -> bool: ...


class PhantomMeta(abc.ABCMeta):
Expand Down Expand Up @@ -73,21 +72,18 @@ def parse(cls: type[Derived], instance: object) -> Derived:

@classmethod
@abc.abstractmethod
def __instancecheck__(cls, instance: object) -> bool:
...
def __instancecheck__(cls, instance: object) -> bool: ...

@classmethod
def __get_validators__(cls: type[Derived]) -> Iterator[Callable[[object], Derived]]:
"""Hook that makes phantom types compatible with pydantic."""
yield cls.parse


class AbstractInstanceCheck(TypeError):
...
class AbstractInstanceCheck(TypeError): ...


class MutableType(TypeError):
...
class MutableType(TypeError): ...


class Phantom(PhantomBase, Generic[T]):
Expand Down
6 changes: 2 additions & 4 deletions src/phantom/_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
from typing_extensions import get_origin


class UnresolvedClassAttribute(NotImplementedError):
...
class UnresolvedClassAttribute(NotImplementedError): ...


def resolve_class_attr(
Expand Down Expand Up @@ -125,8 +124,7 @@ def is_not_known_mutable_type(type_: BoundType) -> TypeGuard[NotKnownMutableType
return not (
any(is_subtype(type_, mutable_type) for mutable_type in mutable)
or (
is_dataclass(type_)
and not type_.__dataclass_params__.frozen # type: ignore[union-attr]
is_dataclass(type_) and not type_.__dataclass_params__.frozen # type: ignore[union-attr]
)
)

Expand Down
66 changes: 22 additions & 44 deletions src/phantom/_utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,58 @@

@runtime_checkable
class _SupportsLt(Protocol[T_contra]):
def __lt__(self, other: T_contra) -> bool:
...
def __lt__(self, other: T_contra) -> bool: ...


class SupportsLt(
_SupportsLt[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsLe(Protocol[T_contra]):
def __le__(self, other: T_contra) -> bool:
...
def __le__(self, other: T_contra) -> bool: ...


class SupportsLe(
_SupportsLe[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsGt(Protocol[T_contra]):
def __gt__(self, other: T_contra) -> bool:
...
def __gt__(self, other: T_contra) -> bool: ...


class SupportsGt(
_SupportsGt[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsGe(Protocol[T_contra]):
def __ge__(self, other: T_contra) -> bool:
...
def __ge__(self, other: T_contra) -> bool: ...


class SupportsGe(
_SupportsGe[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsEq(Protocol):
def __eq__(self, other: object) -> bool:
...
def __eq__(self, other: object) -> bool: ...


class SupportsEq(Protocol, metaclass=CachingProtocolMeta):
...
class SupportsEq(Protocol, metaclass=CachingProtocolMeta): ...


@runtime_checkable
Expand All @@ -82,78 +72,66 @@ class _Comparable(
SupportsGe[T_contra],
SupportsEq,
Protocol[T_contra],
):
...
): ...


class Comparable(
_Comparable[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsLeGe(SupportsLe[T_contra], SupportsGe[T_contra], Protocol[T_contra]):
...
class _SupportsLeGe(SupportsLe[T_contra], SupportsGe[T_contra], Protocol[T_contra]): ...


class SupportsLeGe(
_SupportsLeGe[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsLeGt(SupportsLe[T_contra], SupportsGt[T_contra], Protocol[T_contra]):
...
class _SupportsLeGt(SupportsLe[T_contra], SupportsGt[T_contra], Protocol[T_contra]): ...


class SupportsLeGt(
_SupportsLeGt[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsLtGe(SupportsLt[T_contra], SupportsGe[T_contra], Protocol[T_contra]):
...
class _SupportsLtGe(SupportsLt[T_contra], SupportsGe[T_contra], Protocol[T_contra]): ...


class SupportsLtGe(
_SupportsLtGe[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


class _SupportsLtGt(SupportsLt[T_contra], SupportsGt[T_contra], Protocol[T_contra]):
...
class _SupportsLtGt(SupportsLt[T_contra], SupportsGt[T_contra], Protocol[T_contra]): ...


class SupportsLtGt(
_SupportsLtGt[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
):
...
): ...


@runtime_checkable
class _SupportsMod(Protocol[T_contra, U_co]):
def __mod__(self, other: T_contra) -> U_co:
...
def __mod__(self, other: T_contra) -> U_co: ...


class SupportsMod(
_SupportsMod[T_contra, U_co],
Protocol[T_contra, U_co],
metaclass=CachingProtocolMeta,
):
...
): ...
1 change: 1 addition & 0 deletions src/phantom/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Types describing objects that coerce to either ``True`` or ``False`` respectively when
calling ``bool()`` on them.
"""

from __future__ import annotations

from typing import TYPE_CHECKING
Expand Down
1 change: 1 addition & 0 deletions src/phantom/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
You can install python-dateutil by using the ``[dateutil]`` or ``[all]`` extras.
"""

from __future__ import annotations

import datetime
Expand Down
6 changes: 2 additions & 4 deletions src/phantom/errors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class BoundError(TypeError):
...
class BoundError(TypeError): ...


class MissingDependency(Exception):
...
class MissingDependency(Exception): ...
1 change: 1 addition & 0 deletions src/phantom/ext/phonenumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
$ python3 -m pip install phantom-types[phonenumbers]
"""

from __future__ import annotations

from typing import Final
Expand Down
9 changes: 3 additions & 6 deletions src/phantom/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
.. code-block:: python
class VolumeLevel(int, Inclusive, low=0, high=100):
...
class VolumeLevel(int, Inclusive, low=0, high=100): ...
There is also a set of concrete ready-to-use interval types provided, that use predicate
functions from :py:mod:`phantom.predicates.interval`.
Expand Down Expand Up @@ -43,16 +42,14 @@ def take_portion(portion: Portion, whole: Natural) -> float:


class IntervalCheck(Protocol):
def __call__(self, a: N, b: N) -> Predicate[N]:
...
def __call__(self, a: N, b: N) -> Predicate[N]: ...


inf: Final = float("inf")
neg_inf: Final = float("-inf")


class _NonScalarBounds(Exception):
...
class _NonScalarBounds(Exception): ...


def _get_scalar_int_bounds(
Expand Down
4 changes: 2 additions & 2 deletions src/phantom/iso3166.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
countries: tuple[CountryCode] = ("SE", "DK", ParsedAlpha2.parse("FR"))
"""

from __future__ import annotations

from typing import Final
Expand Down Expand Up @@ -292,8 +293,7 @@
is_alpha2_country_code = contained(ALPHA2)


class InvalidCountryCode(TypeError):
...
class InvalidCountryCode(TypeError): ...


def normalize_alpha2_country_code(country_code: str) -> ParsedAlpha2:
Expand Down
1 change: 1 addition & 0 deletions src/phantom/negated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
eliminate the easy mistake of forgetting to wrap a string value in a containing
sequence.
"""

from __future__ import annotations

from collections.abc import Sequence
Expand Down
4 changes: 2 additions & 2 deletions src/phantom/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
.. code-block:: python
class Greeting(Match, pattern=r"^(Hi|Hello)"):
...
class Greeting(Match, pattern=r"^(Hi|Hello)"): ...
assert isinstance("Hello Jane!", Greeting)
"""

from __future__ import annotations

import re
Expand Down
Loading

0 comments on commit d9f5907

Please sign in to comment.