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

Error with from __future__ import annotations #43

Open
LEv145 opened this issue May 31, 2022 · 5 comments
Open

Error with from __future__ import annotations #43

LEv145 opened this issue May 31, 2022 · 5 comments

Comments

@LEv145
Copy link

LEv145 commented May 31, 2022

from __future__ import annotations

import dataconf

from dataclasses import dataclass


@dataclass
class Model():
    token: str
    
dataconf.env("TEST_", Model)

Error:

Traceback (most recent call last):
  File "main.py", line 13, in <module>
    dataconf.env("ITBUTKA_", Model)
  File "/.venv/lib/python3.9/site-packages/dataconf/main.py", line 64, in env
    return multi.env(prefix, **kwargs).on(clazz)
  File "/.venv/lib/python3.9/site-packages/dataconf/main.py", line 57, in on
    return parse(conf, clazz, self.strict, **self.kwargs)
  File "/.venv/lib/python3.9/site-packages/dataconf/main.py", line 16, in parse
    return utils.__parse(conf, clazz, "", strict, ignore_unexpected)
  File "/.venv/lib/python3.9/site-packages/dataconf/utils.py", line 68, in __parse
    fs[f.name] = __parse(
  File "/.venv/lib/python3.9/site-packages/dataconf/utils.py", line 186, in __parse
    for child_clazz in sorted(clazz.__subclasses__(), key=lambda c: c.__name__):
AttributeError: 'str' object has no attribute '__subclasses__'

Process finished with exit code 1
@LEv145 LEv145 changed the title Bug with from __future__ import annotations Error with from __future__ import annotations May 31, 2022
zifeo added a commit that referenced this issue Jun 1, 2022
@zifeo
Copy link
Owner

zifeo commented Jun 1, 2022

@LEv145 Thank you for your report. PEP 563 (and its backport from __future__ import annotations) seems to introduce a change in annotations evaluation that will have a wide impact on type based logic/libraries.

You can find an attempt to support the change the this branch:

pip install --upgrade git+https://github.com/zifeo/dataconf.git@annotations
poetry add git+https://github.com/zifeo/dataconf.git@annotations

However as this change has been delayed (3.10), is still a bit buggy (see Python bug tracker) and does not offer (yet?) an elegant way around, I will wait until more info and stability are available. The final fix will likely be somehow different.

@zifeo
Copy link
Owner

zifeo commented Jul 24, 2022

Dataconf 2.0.0 has been back-ported to support branch.

@ghost
Copy link

ghost commented Sep 19, 2023

This is broken again on 2.2.1, unfortunately. (Python 3.11, MacOS).

@zifeo
Copy link
Owner

zifeo commented Sep 24, 2023

@dargueta-copilotiq v2.2.2 has been backported, let me know if you find any issue

@ghost
Copy link

ghost commented Sep 27, 2023

Looks good to me. Thanks!

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

No branches or pull requests

2 participants