Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Bump mypy and goose dependencies #318

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .goose/check-manifest/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"source_dependencies":["check-manifest","setuptools-scm==8.1.0","setuptools==74.1.2","wheel==0.44.0"],"lock_files":[{"path":"requirements.txt","checksum":"sha256:b20035ad9215b0fcfab6ed7888d9eba3c135901cc3f3b38258031154db8eec0f"}],"checksum":"sha256:d22cd331fc8a6160e0bafccf35e12ba887664bf07caa3fbee86aea1486b487f6"}
{"source_dependencies":["check-manifest","setuptools-scm==8.1.0","setuptools==74.1.2","wheel==0.44.0"],"lock_files":[{"path":"requirements.txt","checksum":"sha256:1924fe035132f153b19c1a0c2fb86788ef3c8c5e75736cea527c80fe46d4a4a3"}],"checksum":"sha256:47fbe3314bc85b3cb62313bedb71c6bf1c7d5d11e94cf000e02acacb2c6e7ea0"}
6 changes: 3 additions & 3 deletions .goose/check-manifest/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ check-manifest==0.49 \
packaging==24.1 \
--hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \
--hash=sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124
pyproject-hooks==1.1.0 \
--hash=sha256:4b37730834edbd6bd37f26ece6b44802fb1c1ee2ece0e54ddff8bfc06db86965 \
--hash=sha256:7ceeefe9aec63a1064c18d939bdc3adf2d8aa1988a510afec15151578b232aa2
pyproject-hooks==1.2.0 \
--hash=sha256:1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8 \
--hash=sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913
setuptools==74.1.2 \
--hash=sha256:5f4c08aa4d3ebcb57a50c33b1b07e94315d7fc7230f7115e47fc99776c8ce308 \
--hash=sha256:95b40ed940a1c67eb70fc099094bd6e99c6ee7c23aa2306f4d2697ba7916f9c6
Expand Down
2 changes: 1 addition & 1 deletion .goose/python/manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"source_dependencies":["blacken-docs","check-jsonschema","editorconfig-checker","pre-commit-hooks","ruff"],"lock_files":[{"path":"requirements.txt","checksum":"sha256:140c1d41bca5c83cae63593d759d20bf957ff8b5fe5b9779a9ae8bd0072aea08"}],"checksum":"sha256:8210de127816e99ea1e0663462de57123730f998f7afe8dfe5b40add21f4b5e3"}
{"source_dependencies":["blacken-docs","check-jsonschema","editorconfig-checker","pre-commit-hooks","ruff"],"lock_files":[{"path":"requirements.txt","checksum":"sha256:b3df3c12640be9532b30433c67d5d5be94ce8a8b8f1a46a0b49bcc3d36bbad3a"}],"checksum":"sha256:1d0b3c94d1ba82cecd3be0a18f75bf57e4471df7df1834bd63d786fa3f34587b"}
44 changes: 22 additions & 22 deletions .goose/python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ charset-normalizer==3.3.2 \
--hash=sha256:fb69256e180cb6c8a894fee62b3afebae785babc1ee98b81cdf68bbca1987f33 \
--hash=sha256:fd1abc0d89e30cc4e02e4064dc67fcc51bd941eb395c502aac3ec19fab46b519 \
--hash=sha256:ff8fa367d09b717b2a17a052544193ad76cd49979c805768879cb63d9ca50561
check-jsonschema==0.29.2 \
--hash=sha256:6470ff23d848a26b1e77db1141827002f5fff3138295d3345c19b2410d345aa0 \
--hash=sha256:a633aae257f16e5298853edf18fd30ab94878fd88bd6b91902cd7158151c675d
check-jsonschema==0.29.3 \
--hash=sha256:3838b6d6da536496516d08a1779e7a11737628f84b444fe95d397b96fc8cc73f \
--hash=sha256:58d0486e951811744549fa40411e64a6d74bd88c94d9d7fd061e5bf635ff689c
click==8.1.7 \
--hash=sha256:ae74fb96c20a0277a1d615f1e4d73c8414f5a98db8b799a7931d1582f3390c28 \
--hash=sha256:ca9853ad459e787e2192211578cc907e7594e294c7ccc834310722b41b9ca6de
Expand Down Expand Up @@ -421,25 +421,25 @@ ruamel-yaml-clib==0.2.8 \
--hash=sha256:edaef1c1200c4b4cb914583150dcaa3bc30e592e907c01117c08b13a07255ec2 \
--hash=sha256:f481f16baec5290e45aebdc2a5168ebc6d35189ae6fea7a58787613a25f6e875 \
--hash=sha256:fff3573c2db359f091e1589c3d7c5fc2f86f5bdb6f24252c2d8e539d4e45f412
ruff==0.6.7 \
--hash=sha256:02b083770e4cdb1495ed313f5694c62808e71764ec6ee5db84eedd82fd32d8f5 \
--hash=sha256:08277b217534bfdcc2e1377f7f933e1c7957453e8a79764d004e44c40db923f2 \
--hash=sha256:0c05fd37013de36dfa883a3854fae57b3113aaa8abf5dea79202675991d48624 \
--hash=sha256:17a86aac6f915932d259f7bec79173e356165518859f94649d8c50b81ff087e9 \
--hash=sha256:2f0b62056246234d59cbf2ea66e84812dc9ec4540518e37553513392c171cb18 \
--hash=sha256:44e52129d82266fa59b587e2cd74def5637b730a69c4542525dfdecfaae38bd5 \
--hash=sha256:525201b77f94d2b54868f0cbe5edc018e64c22563da6c5c2e5c107a4e85c1c0d \
--hash=sha256:533d66b7774ef224e7cf91506a7dafcc9e8ec7c059263ec46629e54e7b1f90ab \
--hash=sha256:590445eec5653f36248584579c06252ad2e110a5d1f32db5420de35fb0e1c977 \
--hash=sha256:6b1462fa56c832dc0cea5b4041cfc9c97813505d11cce74ebc6d1aae068de36b \
--hash=sha256:8854450839f339e1049fdbe15d875384242b8e85d5c6947bb2faad33c651020b \
--hash=sha256:9ba4efe5c6dbbb58be58dd83feedb83b5e95c00091bf09987b4baf510fee5c99 \
--hash=sha256:a0e1655868164e114ba43a908fd2d64a271a23660195017c17691fb6355d59bb \
--hash=sha256:a939ca435b49f6966a7dd64b765c9df16f1faed0ca3b6f16acdf7731969deb35 \
--hash=sha256:b28f0d5e2f771c1fe3c7a45d3f53916fc74a480698c4b5731f0bea61e52137c8 \
--hash=sha256:b3f8822defd260ae2460ea3832b24d37d203c3577f48b055590a426a722d50ef \
--hash=sha256:c6707a32e03b791f4448dc0dce24b636cbcdee4dd5607adc24e5ee73fd86c00a \
--hash=sha256:f49c9caa28d9bbfac4a637ae10327b3db00f47d038f3fbb2195c4d682e925b14
ruff==0.6.8 \
--hash=sha256:007dee844738c3d2e6c24ab5bc7d43c99ba3e1943bd2d95d598582e9c1b27750 \
--hash=sha256:1085c455d1b3fdb8021ad534379c60353b81ba079712bce7a900e834859182fa \
--hash=sha256:27b87e1801e786cd6ede4ada3faa5e254ce774de835e6723fd94551464c56b8c \
--hash=sha256:5fd0d4b7b1457c49e435ee1e437900ced9b35cb8dc5178921dfb7d98d65a08d0 \
--hash=sha256:677e03c00f37c66cea033274295a983c7c546edea5043d0c798833adf4cf4c6f \
--hash=sha256:6cfb227b932ba8ef6e56c9f875d987973cd5e35bc5d05f5abf045af78ad8e098 \
--hash=sha256:6ef0411eccfc3909269fed47c61ffebdcb84a04504bafa6b6df9b85c27e813b0 \
--hash=sha256:6f5a2f17c7d32991169195d52a04c95b256378bbf0de8cb98478351eb70d526f \
--hash=sha256:70edf6a93b19481affd287d696d9e311388d808671bc209fb8907b46a8c3af44 \
--hash=sha256:77944bca110ff0a43b768f05a529fecd0706aac7bcce36d7f1eeb4cbfca5f0f2 \
--hash=sha256:792213f7be25316f9b46b854df80a77e0da87ec66691e8f012f887b4a671ab5a \
--hash=sha256:8d3bb2e3fbb9875172119021a13eed38849e762499e3cfde9588e4b4d70968dc \
--hash=sha256:9f1476236b3eacfacfc0f66aa9e6cd39f2a624cb73ea99189556015f27c0bdeb \
--hash=sha256:a5bf44b1aa0adaf6d9d20f86162b34f7c593bfedabc51239953e446aefc8ce18 \
--hash=sha256:cd48f945da2a6334f1793d7f701725a76ba93bf3d73c36f6b21fb04d5338dcf5 \
--hash=sha256:ce60058d3cdd8490e5e5471ef086b3f1e90ab872b548814e35930e21d848c9ce \
--hash=sha256:ec0517dc0f37cad14a5319ba7bba6e7e339d03fbf967a6d69b0907d61be7a263 \
--hash=sha256:f8034b19b993e9601f2ddf2c517451e17a6ab5cdb1c13fdff50c1442a7171d87
urllib3==2.2.3 \
--hash=sha256:ca899ca043dcb1bafa3e262d73aa25c465bfb49e0bd9dd5d59f1d0acba2f8fac \
--hash=sha256:e7d814a81dad81e6caf2ec9fdedb284ecc9c73076b62654547cc64ccdcae26e9
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test = [
]
type-check = [
"phantom-types[all]",
"mypy==1.4.1",
"mypy",
"pytest",
"types-python-dateutil",
]
Expand Down
2 changes: 1 addition & 1 deletion src/phantom/_utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +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[attr-defined]
)
)

Expand Down
30 changes: 29 additions & 1 deletion src/phantom/_utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,14 @@ class SupportsGe(
@runtime_checkable
class _SupportsEq(Protocol):
def __eq__(self, other: object) -> bool: ...
def __hash__(self) -> int: ...


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


@runtime_checkable
Expand All @@ -82,6 +87,29 @@ class Comparable(
): ...


@runtime_checkable
class _SupportsFloat(Protocol):
def __float__(self) -> float: ...


class SupportsFloat(_SupportsFloat, Protocol, metaclass=CachingProtocolMeta): ...


@runtime_checkable
class _FloatComparable(
SupportsFloat,
Comparable[T_contra],
Protocol[T_contra],
): ...


class FloatComparable(
_FloatComparable[T_contra],
Protocol[T_contra],
metaclass=CachingProtocolMeta,
): ...


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

Expand Down
4 changes: 2 additions & 2 deletions src/phantom/datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parse(cls, instance: object) -> TZAware:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "A date-time with timezone data.",
}

Expand All @@ -102,7 +102,7 @@ def parse(cls, instance: object) -> TZNaive:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "A date-time without timezone data.",
"format": "date-time-naive",
}
Expand Down
4 changes: 2 additions & 2 deletions src/phantom/ext/phonenumbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PhoneNumber(str, Phantom, predicate=is_phone_number):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "A valid E.164 phone number.",
"type": "string",
"format": "E.164",
Expand All @@ -100,6 +100,6 @@ def parse(cls, instance: object) -> FormattedPhoneNumber:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"title": "PhoneNumber",
}
43 changes: 22 additions & 21 deletions src/phantom/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def take_portion(portion: Portion, whole: Natural) -> float:
from . import _hypothesis
from ._utils.misc import resolve_class_attr
from ._utils.types import Comparable
from ._utils.types import FloatComparable
from ._utils.types import SupportsEq
from .predicates import interval
from .schema import Schema
Expand Down Expand Up @@ -93,13 +94,13 @@ def _get_scalar_float_bounds(

if low is not None:
try:
low = float(low) # type: ignore[arg-type]
low = float(low)
except TypeError as excpetion:
raise _NonScalarBounds from excpetion

if high is not None:
try:
high = float(high) # type: ignore[arg-type]
high = float(high)
except TypeError as exception:
raise _NonScalarBounds from exception

Expand Down Expand Up @@ -136,14 +137,14 @@ class Interval(Phantom[Comparable], bound=Comparable, abstract=True):
"""

__check__: IntervalCheck
__low__: Comparable
__high__: Comparable
__low__: FloatComparable
__high__: FloatComparable

def __init_subclass__(
cls,
check: IntervalCheck | None = None,
low: Comparable | None = None,
high: Comparable | None = None,
low: FloatComparable | None = None,
high: FloatComparable | None = None,
**kwargs: Any,
) -> None:
_resolve_bound(cls, "__low__", low, neg_inf)
Expand Down Expand Up @@ -177,13 +178,13 @@ class Exclusive(Interval, check=interval.exclusive, abstract=True):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": (
f"A value in the exclusive range ({_format_limit(cls.__low__)}, "
f"{_format_limit(cls.__high__)})."
),
"exclusiveMinimum": cls.__low__ if cls.__low__ != neg_inf else None,
"exclusiveMaximum": cls.__high__ if cls.__high__ != inf else None,
"exclusiveMinimum": float(cls.__low__) if cls.__low__ != neg_inf else None,
"exclusiveMaximum": float(cls.__high__) if cls.__high__ != inf else None,
}

@classmethod
Expand All @@ -209,13 +210,13 @@ class Inclusive(Interval, check=interval.inclusive, abstract=True):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": (
f"A value in the inclusive range [{_format_limit(cls.__low__)}, "
f"{_format_limit(cls.__high__)}]."
),
"minimum": cls.__low__ if cls.__low__ != neg_inf else None,
"maximum": cls.__high__ if cls.__high__ != inf else None,
"minimum": float(cls.__low__) if cls.__low__ != neg_inf else None,
"maximum": float(cls.__high__) if cls.__high__ != inf else None,
}

@classmethod
Expand All @@ -237,13 +238,13 @@ class ExclusiveInclusive(Interval, check=interval.exclusive_inclusive, abstract=
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": (
f"A value in the half-open range ({_format_limit(cls.__low__)}, "
f"{_format_limit(cls.__high__)}]."
),
"exclusiveMinimum": cls.__low__ if cls.__low__ != neg_inf else None,
"maximum": cls.__high__ if cls.__high__ != inf else None,
"exclusiveMinimum": float(cls.__low__) if cls.__low__ != neg_inf else None,
"maximum": float(cls.__high__) if cls.__high__ != inf else None,
}

@classmethod
Expand All @@ -265,13 +266,13 @@ class InclusiveExclusive(Interval, check=interval.inclusive_exclusive, abstract=
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": (
f"A value in the half-open range [{_format_limit(cls.__low__)}, "
f"{_format_limit(cls.__high__)})."
),
"minimum": cls.__low__ if cls.__low__ != neg_inf else None,
"exclusiveMaximum": cls.__high__ if cls.__high__ != inf else None,
"minimum": float(cls.__low__) if cls.__low__ != neg_inf else None,
"exclusiveMaximum": float(cls.__high__) if cls.__high__ != inf else None,
}

@classmethod
Expand All @@ -293,7 +294,7 @@ class Natural(int, InclusiveExclusive, low=0):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "An integer value in the inclusive range [0, ∞).",
}

Expand All @@ -304,7 +305,7 @@ class NegativeInt(int, ExclusiveInclusive, high=0):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "An integer value in the inclusive range (-∞, 0].",
}

Expand All @@ -315,6 +316,6 @@ class Portion(float, Inclusive, low=0, high=1):
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "A float value in the inclusive range [0, 1].",
}
2 changes: 1 addition & 1 deletion src/phantom/iso3166.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def parse(cls, instance: object) -> ParsedAlpha2:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "ISO3166-1 alpha-2 country code",
"examples": ["NR", "KZ", "ET", "VC", "AE", "NZ", "SX", "XK", "AX"],
"format": "iso3166-1 alpha-2",
Expand Down
4 changes: 3 additions & 1 deletion src/phantom/negated.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ def __register_strategy__(cls) -> _hypothesis.HypothesisStrategy:
from hypothesis.strategies import from_type
from hypothesis.strategies import tuples

def create_strategy(type_: type[T]) -> _hypothesis.SearchStrategy[T] | None:
def create_strategy(
type_: type[T],
) -> _hypothesis.SearchStrategy[tuple[T, ...]] | None:
(inner_type,) = get_args(type_)
return tuples(from_type(inner_type))

Expand Down
4 changes: 2 additions & 2 deletions src/phantom/re.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init_subclass__(cls, pattern: Pattern[str] | str, **kwargs: Any) -> None:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": (
"A string starting with a match of the format regular expression."
),
Expand All @@ -71,7 +71,7 @@ def __init_subclass__(cls, pattern: Pattern[str] | str, **kwargs: Any) -> None:
@classmethod
def __schema__(cls) -> Schema:
return {
**super().__schema__(), # type: ignore[misc]
**super().__schema__(),
"description": "A string that matches the format regular expression.",
"format": str(cls.__pattern__.pattern),
}
Expand Down
Loading