Skip to content

Commit

Permalink
Add attrs namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Dec 15, 2021
1 parent e79b0a7 commit 5a3fb7a
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 58 deletions.
6 changes: 2 additions & 4 deletions conftest.py
@@ -1,10 +1,8 @@
from __future__ import absolute_import, division, print_function

import sys

from hypothesis import HealthCheck, settings

from attr._compat import PY310
from attr._compat import PY36, PY310


def pytest_configure(config):
Expand All @@ -16,7 +14,7 @@ def pytest_configure(config):


collect_ignore = []
if sys.version_info[:2] < (3, 6):
if not PY36:
collect_ignore.extend(
[
"tests/test_annotations.py",
Expand Down
31 changes: 29 additions & 2 deletions src/attr/_next_gen.py
Expand Up @@ -5,16 +5,17 @@

from functools import partial

from attr.exceptions import UnannotatedAttributeError

from . import setters
from ._funcs import asdict as _asdict
from ._funcs import astuple as _astuple
from ._make import (
NOTHING,
_frozen_setattrs,
_ng_default_on_setattr,
attrib,
attrs,
)
from .exceptions import UnannotatedAttributeError


def define(
Expand Down Expand Up @@ -168,3 +169,29 @@ def field(
order=order,
on_setattr=on_setattr,
)


def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
"""
Same as `attr.asdict`, except that collections types are always retained
and dict is always used as the dict_factory.
.. versionadded:: 21.3.0
"""
return _asdict(
inst=inst,
recurse=recurse,
filter=filter,
value_serializer=value_serializer,
retain_collection_types=True,
)


def astuple(inst, *, recurse=True, filter=None):
"""
Same as `attr.astuple`, except that collections types are always retained
and `tuple`` is always used as the tuple_factory.
.. versionadded:: 21.3.0
"""
return _astuple(inst=inst, recurse=recurse, filter=filter)
71 changes: 71 additions & 0 deletions src/attrs/__init__.py
@@ -0,0 +1,71 @@
from attr import (
NOTHING,
Attribute,
Factory,
__author__,
__copyright__,
__description__,
__doc__,
__email__,
__license__,
__title__,
__url__,
__version__,
__version_info__,
assoc,
cmp_using,
converters,
define,
evolve,
exceptions,
field,
fields,
fields_dict,
filters,
frozen,
has,
make_class,
mutable,
resolve_types,
setters,
validate,
validators,
)
from attr._next_gen import asdict, astuple


__all__ = [
"__author__",
"__copyright__",
"__description__",
"__doc__",
"__email__",
"__license__",
"__title__",
"__url__",
"__version__",
"__version_info__",
"asdict",
"assoc",
"astuple",
"Attribute",
"cmp_using",
"converters",
"define",
"evolve",
"exceptions",
"Factory",
"field",
"fields_dict",
"fields",
"filters",
"frozen",
"has",
"make_class",
"mutable",
"NOTHING",
"resolve_types",
"setters",
"validate",
"validators",
]

0 comments on commit 5a3fb7a

Please sign in to comment.