Skip to content

Commit fe3c53e

Browse files
committed
Fix imports from attrs submodules
1 parent a6a4f79 commit fe3c53e

File tree

9 files changed

+82
-7
lines changed

9 files changed

+82
-7
lines changed

src/attr/converters.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515

1616
__all__ = [
17-
"pipe",
18-
"optional",
1917
"default_if_none",
18+
"optional",
19+
"pipe",
20+
"to_bool",
2021
]
2122

2223

src/attrs/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@
1414
__version_info__,
1515
assoc,
1616
cmp_using,
17-
converters,
1817
define,
1918
evolve,
20-
exceptions,
2119
field,
2220
fields,
2321
fields_dict,
24-
filters,
2522
frozen,
2623
has,
2724
make_class,
2825
mutable,
2926
resolve_types,
30-
setters,
3127
validate,
32-
validators,
3328
)
3429
from attr._next_gen import asdict, astuple
3530

31+
from . import converters, exceptions, filters, setters, validators
32+
3633

3734
__all__ = [
3835
"__author__",

src/attrs/converters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from attr.converters import * # noqa

src/attrs/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from attr.exceptions import * # noqa

src/attrs/filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from attr.filters import * # noqa

src/attrs/setters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from attr.setters import * # noqa

src/attrs/validators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from attr.validators import * # noqa

tests/test_next_gen.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,49 @@ def test_smoke(self):
390390
assert attrs.asdict(inst) == _attr.asdict(
391391
inst, retain_collection_types=True
392392
)
393+
394+
395+
class TestImports:
396+
"""
397+
Verify our re-imports and mirroring works.
398+
"""
399+
400+
def test_converters(self):
401+
"""
402+
Importing from attrs.converters works.
403+
"""
404+
from attrs.converters import optional
405+
406+
assert optional is _attr.converters.optional
407+
408+
def test_exceptions(self):
409+
"""
410+
Importing from attrs.exceptions works.
411+
"""
412+
from attrs.exceptions import FrozenError
413+
414+
assert FrozenError is _attr.exceptions.FrozenError
415+
416+
def test_filters(self):
417+
"""
418+
Importing from attrs.filters works.
419+
"""
420+
from attrs.filters import include
421+
422+
assert include is _attr.filters.include
423+
424+
def test_setters(self):
425+
"""
426+
Importing from attrs.setters works.
427+
"""
428+
from attrs.setters import pipe
429+
430+
assert pipe is _attr.setters.pipe
431+
432+
def test_validators(self):
433+
"""
434+
Importing from attrs.validators works.
435+
"""
436+
from attrs.validators import and_
437+
438+
assert and_ is _attr.validators.and_

tests/typing_example.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,3 +390,29 @@ class MatchArgs2:
390390
# NG versions of asdict/astuple
391391
attrs.asdict(MatchArgs2(1, 2))
392392
attrs.astuple(MatchArgs2(1, 2))
393+
394+
395+
def importing_from_attr() -> None:
396+
"""
397+
Use a function to keep the ns clean.
398+
"""
399+
from attr.converters import optional
400+
from attr.exceptions import FrozenError
401+
from attr.filters import include
402+
from attr.setters import frozen
403+
from attr.validators import and_
404+
405+
assert optional and FrozenError and include and frozen and and_
406+
407+
408+
def importing_from_attrs() -> None:
409+
"""
410+
Use a function to keep the ns clean.
411+
"""
412+
from attrs.converters import optional
413+
from attrs.exceptions import FrozenError
414+
from attrs.filters import include
415+
from attrs.setters import frozen
416+
from attrs.validators import and_
417+
418+
assert optional and FrozenError and include and frozen and and_

0 commit comments

Comments
 (0)