Skip to content

Commit

Permalink
Update attrs and use attrs.NothingType (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinche authored Jan 12, 2025
1 parent 01e2224 commit d987382
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 19 deletions.
13 changes: 5 additions & 8 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test = [
"pytest>=8.3.2",
"pytest-benchmark>=4.0.0",
"immutables>=0.20",
"typing-extensions>=4.7.1",
"coverage>=7.6.1",
"pytest-xdist>=3.6.1",
]
Expand All @@ -22,7 +21,6 @@ docs = [
"myst-parser>=1.0.0",
"pendulum>=2.1.2",
"sphinx-autobuild",
"typing-extensions>=4.8.0",
]
bench = [
"pyperf>=2.6.1",
Expand All @@ -42,7 +40,7 @@ authors = [
{name = "Tin Tvrtkovic", email = "tinchester@gmail.com"},
]
dependencies = [
"attrs>=23.1.0",
"attrs>=24.3.0",
"typing-extensions>=4.12.2",
"exceptiongroup>=1.1.1; python_version < '3.11'",
]
Expand Down
4 changes: 2 additions & 2 deletions src/cattrs/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from typing import Sequence as TypingSequence
from typing import Set as TypingSet

from attrs import NOTHING, Attribute, Factory, resolve_types
from attrs import NOTHING, Attribute, Factory, NothingType, resolve_types
from attrs import fields as attrs_fields
from attrs import fields_dict as attrs_fields_dict

Expand Down Expand Up @@ -296,7 +296,7 @@ def get_newtype_base(typ: Any) -> Optional[type]:
return None


def get_notrequired_base(type) -> "Union[Any, Literal[NOTHING]]":
def get_notrequired_base(type) -> Union[Any, NothingType]:
if is_annotated(type):
# Handle `Annotated[NotRequired[int]]`
type = get_args(type)[0]
Expand Down
8 changes: 5 additions & 3 deletions src/cattrs/cols.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from collections import defaultdict
from collections.abc import Iterable
from collections.abc import Callable, Iterable
from functools import partial
from typing import (
TYPE_CHECKING,
Expand All @@ -15,7 +15,7 @@
get_type_hints,
)

from attrs import NOTHING, Attribute
from attrs import NOTHING, Attribute, NothingType

from ._compat import (
ANIES,
Expand Down Expand Up @@ -294,7 +294,9 @@ def is_defaultdict(type: Any) -> bool:


def defaultdict_structure_factory(
type: type[defaultdict], converter: BaseConverter, default_factory: Any = NOTHING
type: type[defaultdict],
converter: BaseConverter,
default_factory: Callable[[], Any] | NothingType = NOTHING,
) -> StructureHook:
"""A structure hook factory for defaultdicts.
Expand Down
6 changes: 3 additions & 3 deletions src/cattrs/strategies/_unions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from typing import Any, Callable, Literal, Union
from typing import Any, Callable, Union

from attrs import NOTHING
from attrs import NOTHING, NothingType

from cattrs import BaseConverter
from cattrs._compat import get_newtype_base, is_literal, is_subclass, is_union_type
Expand All @@ -23,7 +23,7 @@ def configure_tagged_union(
converter: BaseConverter,
tag_generator: Callable[[type], str] = default_tag_generator,
tag_name: str = "_type",
default: Union[type, Literal[NOTHING]] = NOTHING,
default: Union[type, NothingType] = NOTHING,
) -> None:
"""
Configure the converter so that `union` (which should be a union) is
Expand Down

0 comments on commit d987382

Please sign in to comment.