Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reify object based on base type #22

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_more.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
from collections.abc import Mapping

from unification import var
Expand Down Expand Up @@ -29,6 +30,14 @@ def test_unify_object():
assert stream_eval(_unify_object(Foo(1, 2), Foo(1, x), {})) == {x: 2}


def test_unify_nonstandard_object():
_unify.add((ast.AST, ast.AST, Mapping), _unify_object)
x = var()
assert unify(ast.Num(n=1), ast.Num(n=1), {}) == {}
assert unify(ast.Num(n=1), ast.Num(n=2), {}) is False
assert unify(ast.Num(n=1), ast.Num(n=x), {}) == {x: 1}


def test_reify_object():
x = var()
obj = stream_eval(_reify_object(Foo(1, x), {x: 4}))
Expand All @@ -39,6 +48,14 @@ def test_reify_object():
assert stream_eval(_reify_object(f, {})) is f


def test_reify_nonstandard_object():
_reify.add((ast.AST, Mapping), _reify_object)
x = var()
assert reify(ast.Num(n=1), {}).n == 1
assert reify(ast.Num(n=x), {}).n == x
assert reify(ast.Num(n=x), {x: 2}).n == 2


def test_reify_slots():
class SlotsObject(object):
__slots__ = ["myattr"]
Expand Down
2 changes: 1 addition & 1 deletion unification/more.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _reify_object(o, s):


def _reify_object_dict(o, s):
obj = object.__new__(type(o))
obj = type(o).__new__(type(o))

d = yield _reify(o.__dict__, s)

Expand Down