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

>0.5.8 issue with beartype>0.10.0 #450

Closed
a-mckinley opened this issue Jul 28, 2023 · 3 comments
Closed

>0.5.8 issue with beartype>0.10.0 #450

a-mckinley opened this issue Jul 28, 2023 · 3 comments
Labels
api/v0 bug Something isn't working

Comments

@a-mckinley
Copy link

Description

I realise this is not likely to be a real "bug", but I discovered an issue using dataclasses-json in conjunction with beartype>0.10.0 with dataclasses-json >0.5.8.

Beartype complains about:

beartype.roar.BeartypeDecorHintForwardRefException: Forward reference "dataclasses_json.api.SchemaType[A]" syntactically invalid as module attribute name.

Code snippet that reproduces the issue

from dataclasses import dataclass
from dataclasses_json import dataclass_json
from beartype import beartype


@beartype
@dataclass_json
@dataclass
class Testing(object):
    data: str


t = Testing(data='thing')
print(t)

Describe the results you expected

beartype compatibility working

Python version you are using

3.11.3

Environment description

Working environments:

pip install -U beartype==0.15.0 dataclasses_json==0.5.8
pip install -U beartype==0.10.0 dataclasses_json==0.5.13

Failing environment:

pip install -U beartype==0.15.0 dataclasses_json==0.5.13

@a-mckinley a-mckinley added the bug Something isn't working label Jul 28, 2023
@george-zubrienko
Copy link
Collaborator

@a-mckinley can you try with subclass instead of the annotation?

@a-mckinley
Copy link
Author

Hi @george-zubrienko, changing to use the subclass instead of the decorator eliminates the beartype error.

from dataclasses import dataclass
from dataclasses_json import DataClassJsonMixin
from beartype import beartype


@beartype
@dataclass
class Testing(DataClassJsonMixin):
    data: str


t = Testing(data='thing')
print(t)

@george-zubrienko
Copy link
Collaborator

Decorator has some issues we can't easily solve rn - thus #442 is in discussion. For v0 (current) API, I'd recommend to either avoid the decorator entirely or pair it with the subclass. We are looking into solving issues it causes with v1 API

@george-zubrienko george-zubrienko closed this as not planned Won't fix, can't repro, duplicate, stale Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/v0 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants