Does not work with future annotations
See original GitHub issueA resolution error is raised when you make a promise using annotations. It works if you stop importing the annotations package and use quotation marks.
The following code breaks. If you comment out the first line, the code works.
from __future__ import annotations
from plum import dispatch
class Displacement:
def __init__(self, x, y):
self.x = x
self.y = y
@dispatch
def __add__(self, other: "Displacement") -> "Displacement":
return Displacement(self.x + other.x, self.y + other.y)
@dispatch
def __add__(self, other: int) -> "Displacement":
return Displacement(self.x + other, self.y + other)
if __name__ == "__main__":
d1 = Displacement(1, 2)
d2 = Displacement(3, 4)
print(d1 + d2)
Traceback (most recent call last):
File "C:\Users\gaspa\dev\python\py-chess\src\geometry_copy.py", line 22, in <module>
print(d1 + d2)
File "plum\function.py", line 585, in plum.function._BoundFunction.__call__
File "plum\function.py", line 509, in plum.function.Function.__call__
File "plum\function.py", line 373, in plum.function.Function._resolve_pending_registrations
File "C:\Users\gaspa\.virtualenvs\py-chess-YZvcAOQM\lib\site-packages\plum\type.py", line 436, in is_object
return t.get_types() == (object,)
File "C:\Users\gaspa\.virtualenvs\py-chess-YZvcAOQM\lib\site-packages\plum\type.py", line 259, in get_types
return ptype(self.resolve()).get_types()
File "C:\Users\gaspa\.virtualenvs\py-chess-YZvcAOQM\lib\site-packages\plum\resolvable.py", line 41, in resolve
raise ResolutionError(f"Promise `{self!r}` was not kept.")
plum.resolvable.ResolutionError: Promise `ForwardReferencedType(name="'Displacement'")` was not kept.
Process finished with exit code 1
Issue Analytics
- State:
- Created a year ago
- Comments:37 (18 by maintainers)
Top Results From Across the Web
Can't import annotations from __future__ - Stack Overflow
If I use annotations, they are widely supported in 3.7, so no need for a future. If I run my code on an...
Read more >Annotation issues at runtime - mypy 0.991 documentation
Many of the issues described here are caused by Python trying to evaluate annotations. Future Python versions (potentially Python 3.12) will by default...
Read more >Python 3.6 compatbility not working due to future annotations #5
Hi, I'm currently looking into how to fix this problem. In the meantime, I have created a new release that attempts to allow...
Read more >Future Annotation | Apex Developer Guide
Use the future annotation to identify methods that are executed asynchronously. When you specify future , the method executes when Salesforce has available ......
Read more >Function annotations — Python-Future documentation
Function annotations are a piece of syntax introduced in Python 3.0 that was not backported to Python 2.x. (See PEP 3107: http://www.python.org/dev/peps/pep- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, @gasparyanartur. This is something that will have to be fixed. I imagine that it shouldn’t be too complicated to get right.
@seeM Thanks! Will be solved in the next release.