-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix MultiStrategyDispatch to work with new GenConverter and attrs inh…
…eritance Because the GenConverter specifically handles generating code for attrs classes, and because it registers hooks that don't require function dispatch, singledispatch was preventing subclasses from having code generated for them, because they would trigger the previously-generated base class's structure/unstructure code. This changes MultiStrategyDispatch to allow for a class-based hook to specifically avoid single-dispatch. Since we know that a given attrs class can always have code generated for it, we don't really want to share dispatch across subclasses - like the original Converter, we want to make sure we're structuring each individual attrs class as its own separate type.
- Loading branch information
Peter Gaultney
committed
Jan 24, 2021
1 parent
61c9445
commit a25ca9a
Showing
3 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from cattr.converters import GenConverter | ||
import attr | ||
|
||
|
||
def test_inheritance(): | ||
@attr.s(auto_attribs=True) | ||
class A: | ||
i: int | ||
|
||
@attr.s(auto_attribs=True) | ||
class B(A): | ||
j: int | ||
|
||
converter = GenConverter() | ||
|
||
# succeeds | ||
assert A(1) == converter.structure(dict(i=1), A) | ||
|
||
# fails | ||
assert B(1, 2) == converter.structure(dict(i=1, j=2), B) |