-
-
Notifications
You must be signed in to change notification settings - Fork 386
Forward references #265
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
Comments
This issue was initially motivated by https://github.com/Tinche/cattrs/issues/13. |
GitHub doesn't have enough Emojis for this one. |
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes python-attrs#265
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes python-attrs#265
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes python-attrs#265
As I understand it, and especially with PEP 563 in the picture, I'd argue the current behaviour is the most correct one. Especially as performance was one of the motivations for the change:
|
Is this still relevant with |
Yeah, I haven't really looked into this in depth again yet but I think this is out of scope for attrs now. |
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes python-attrs#265
This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes python-attrs#265
* Add attr.resolve_types This adds `attr.resolve_types` which can be used to resolve forward declarations in classes created using `__annotations__` Fixes #265 * Fix flake8 and doctest * Missed one * Fix lint * Address CR comments Add to stubs Make it a decorator, because why not? * Fix test * Rerun-tests please * Rerun-tests please * Fix another * Fix lint Co-authored-by: David Euresti <[email protected]>
FYI we have |
Hello, there's some food for thought. Imagine a class referencing itself.
This is the proper way of doing this as per mypy. In the case of attrs though:
The string just gets copied into the type attribute.
A.__annotations__
has the same problem. Ideally the type would be the actual class object. Mypy deals with this by having more than one pass when parsing.The first question to answer if whether we should deal with this here, in attrs, or let code making use of the type attribute deal with it. Maybe instead of expecting higher levels to deal with this, Python itself should handle it (although good luck waiting for this :). I think it's worth trying to deal with this problem in attrs, to make it easier for others.
Dealing with just a class referencing itself is very doable. Now imagine circular references.
Not really sure what to do here.
The text was updated successfully, but these errors were encountered: