-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nested backend support where one backend can rely on another via …
…a default.
- Loading branch information
1 parent
d179d70
commit 604446a
Showing
3 changed files
with
33 additions
and
2 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
Empty file.
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,30 @@ | ||
import uarray as ua | ||
|
||
|
||
class Backend: | ||
__ua_domain__ = "ua_tests" | ||
|
||
|
||
def test_nestedbackend(): | ||
obj = object() | ||
be_outer = Backend() | ||
be_outer.__ua_function__ = lambda f, a, kw: obj | ||
|
||
mm1 = ua.generate_multimethod(lambda: (), lambda a, kw, d: (a, kw), "ua_tests") | ||
|
||
def default(*a, **kw): | ||
return mm1(*a, **kw) | ||
|
||
mm2 = ua.generate_multimethod( | ||
lambda: (), lambda a, kw, d: (a, kw), "ua_tests", default=default | ||
) | ||
|
||
be_inner = Backend() | ||
|
||
def be2_ua_func(f, a, kw): | ||
with ua.skip_backend(be_inner): | ||
return f(*a, **kw) | ||
|
||
be_inner.__ua_function__ = be2_ua_func | ||
with ua.set_backend(be_outer), ua.set_backend(be_inner): | ||
assert mm2() is obj |
Isn't the
set_backend
on line 164 redundant now.