Skip to content

Commit 8a137ae

Browse files
committed
Add attrs namespace
1 parent 3833e4f commit 8a137ae

File tree

5 files changed

+160
-57
lines changed

5 files changed

+160
-57
lines changed

887.breaking.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``import attrs`` has finally landed!
2+
As of this release, you can finally import ``attrs`` using its proper name.
3+
4+
Not all names from the ``attr`` namespace have been transferred; most notably ``attr.s`` and ``attr.ib`` are missing.
5+
6+
This feature is at least for one release **provisional**.

conftest.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
from __future__ import absolute_import, division, print_function
22

3-
import sys
4-
53
from hypothesis import HealthCheck, settings
64

7-
from attr._compat import PY310
5+
from attr._compat import PY36, PY310
86

97

108
def pytest_configure(config):
@@ -16,7 +14,7 @@ def pytest_configure(config):
1614

1715

1816
collect_ignore = []
19-
if sys.version_info[:2] < (3, 6):
17+
if not PY36:
2018
collect_ignore.extend(
2119
[
2220
"tests/test_annotations.py",

src/attr/_next_gen.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55

66
from functools import partial
77

8-
from attr.exceptions import UnannotatedAttributeError
9-
108
from . import setters
9+
from ._funcs import asdict as _asdict
10+
from ._funcs import astuple as _astuple
1111
from ._make import (
1212
NOTHING,
1313
_frozen_setattrs,
1414
_ng_default_on_setattr,
1515
attrib,
1616
attrs,
1717
)
18+
from .exceptions import UnannotatedAttributeError
1819

1920

2021
def define(
@@ -168,3 +169,29 @@ def field(
168169
order=order,
169170
on_setattr=on_setattr,
170171
)
172+
173+
174+
def asdict(inst, *, recurse=True, filter=None, value_serializer=None):
175+
"""
176+
Same as `attr.asdict`, except that collections types are always retained
177+
and dict is always used as the dict_factory.
178+
179+
.. versionadded:: 21.3.0
180+
"""
181+
return _asdict(
182+
inst=inst,
183+
recurse=recurse,
184+
filter=filter,
185+
value_serializer=value_serializer,
186+
retain_collection_types=True,
187+
)
188+
189+
190+
def astuple(inst, *, recurse=True, filter=None):
191+
"""
192+
Same as `attr.astuple`, except that collections types are always retained
193+
and `tuple`` is always used as the tuple_factory.
194+
195+
.. versionadded:: 21.3.0
196+
"""
197+
return _astuple(inst=inst, recurse=recurse, filter=filter)

src/attrs/__init__.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from attr import (
2+
NOTHING,
3+
Attribute,
4+
Factory,
5+
__author__,
6+
__copyright__,
7+
__description__,
8+
__doc__,
9+
__email__,
10+
__license__,
11+
__title__,
12+
__url__,
13+
__version__,
14+
__version_info__,
15+
assoc,
16+
cmp_using,
17+
converters,
18+
define,
19+
evolve,
20+
exceptions,
21+
field,
22+
fields,
23+
fields_dict,
24+
filters,
25+
frozen,
26+
has,
27+
make_class,
28+
mutable,
29+
resolve_types,
30+
setters,
31+
validate,
32+
validators,
33+
)
34+
from attr._next_gen import asdict, astuple
35+
36+
37+
__all__ = [
38+
"__author__",
39+
"__copyright__",
40+
"__description__",
41+
"__doc__",
42+
"__email__",
43+
"__license__",
44+
"__title__",
45+
"__url__",
46+
"__version__",
47+
"__version_info__",
48+
"asdict",
49+
"assoc",
50+
"astuple",
51+
"Attribute",
52+
"cmp_using",
53+
"converters",
54+
"define",
55+
"evolve",
56+
"exceptions",
57+
"Factory",
58+
"field",
59+
"fields_dict",
60+
"fields",
61+
"filters",
62+
"frozen",
63+
"has",
64+
"make_class",
65+
"mutable",
66+
"NOTHING",
67+
"resolve_types",
68+
"setters",
69+
"validate",
70+
"validators",
71+
]

0 commit comments

Comments
 (0)