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

can't nest annotable objects with defaults #23

Closed
cpcloud opened this issue Sep 1, 2024 · 2 comments · Fixed by #24
Closed

can't nest annotable objects with defaults #23

cpcloud opened this issue Sep 1, 2024 · 2 comments · Fixed by #24

Comments

@cpcloud
Copy link
Collaborator

cpcloud commented Sep 1, 2024

In [3]: from koerce import Annotable

In [4]: class Bar(Annotable):
   ...:     x: int
   ...:

In [5]: class Foo(Annotable):
   ...:     bar: Bar = Bar(1)
   ...:
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 1
----> 1 class Foo(Annotable):
      2     bar: Bar = Bar(1)

File koerce/_internal.pyx:3169, in koerce._internal.AnnotableMeta.__new__()

File koerce/_internal.pyx:2687, in koerce._internal.Parameter.__init__()

File koerce/_internal.pyx:1391, in koerce._internal.AsCoercible.match()

File koerce/_internal.pyx:3284, in koerce._internal.Annotable.__coerce__()

TypeError: __coerce__() takes exactly 2 positional arguments (1 given)
@cpcloud cpcloud changed the title can't nest annotable objects can't nest annotable objects with defaults Sep 1, 2024
@cpcloud
Copy link
Collaborator Author

cpcloud commented Sep 1, 2024

Without a default, the construction still fails:

In [6]: class Foo(Annotable):
   ...:     bar: Bar
   ...:

In [7]: Foo(Bar(1))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[7], line 1
----> 1 Foo(Bar(1))

File koerce/_internal.pyx:3196, in koerce._internal.AnnotableMeta.__call__()

File koerce/_internal.pyx:3101, in koerce._internal.AnnotableSpec.new()

File koerce/_internal.pyx:1391, in koerce._internal.AsCoercible.match()

File koerce/_internal.pyx:3284, in koerce._internal.Annotable.__coerce__()

TypeError: __coerce__() takes exactly 2 positional arguments (1 given)

@kszucs
Copy link
Owner

kszucs commented Sep 1, 2024

Ooops, can you just delete Annotable.__coerce__? My original idea was to allow coercing dictionaries to annotable objects, but I haven't finished the implementation of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants