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

Add "resolve_types" argument to attrs.define() #1286

Open
sscherfke opened this issue May 19, 2024 · 2 comments · May be fixed by #1390
Open

Add "resolve_types" argument to attrs.define() #1286

sscherfke opened this issue May 19, 2024 · 2 comments · May be fixed by #1390
Labels

Comments

@sscherfke
Copy link
Contributor

sscherfke commented May 19, 2024

Add a resolve_types: bool = ? argument to attrs.define() and call resolve_types() on the new class if True is passed.

Why?

According to the Typed Settings issue tracker, people seem to start playing with postponed annotations.
For Typed Settings to work, annotated types need to be resolved.
We try to automatically do this but it is not always possible to do it.
So people need to do sth. like this:

@attrs.resolve_types
@attrs.define
class Settings:
    opt: int = 0

It would be a bit nicer if they could write

@attrs.define(resolve_types=True)
class Settings:
    opt: int = 0

instead. This would also make it easier to write custom define() partials similar to frozen().

I can create a PR if needed.

@sscherfke
Copy link
Contributor Author

Pydantic automatically does this so I guess users might eventually expected this behavior from attrs, too.

@hynek
Copy link
Member

hynek commented Jul 24, 2024

I'm open to PRs!

@hynek hynek added the Feature label Jul 24, 2024
sscherfke added a commit to sscherfke/attrs that referenced this issue Dec 25, 2024
@sscherfke sscherfke linked a pull request Dec 25, 2024 that will close this issue
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants