-
Notifications
You must be signed in to change notification settings - Fork 2
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
Handling typing.Annotated
#36
Comments
Closed
More details from separate issue: from typing import NewType, Annotated
import sciline as sl
Int = NewType('Int', int)
Str = NewType('Str', str)
AStr = Annotated[Str, 'metadata']
def foo(x: Int) -> AStr:
return Str(str(x))
def bar(s: Str, a: AStr) -> list[str]:
return [s, a]
pl = sl.Pipeline([foo, bar], params={Int: Int(3)})
# Can compute results:
print(pl.compute(Str)) # -> 3
print(pl.compute(list[str])) # -> ['3', '3']
# But the annotation is lost in the graph:
g = pl.get(Str)
print(list(g._graph)) # -> [__main__.Str, __main__.Int]
g = pl.get(list[str])
print(list(g._graph)) # -> [list[str], __main__.Str, __main__.Int]
print(list(g._graph[list[str]].arg_spec.keys())) # -> [__main__.Str, __main__.Str]
# Raises
# sciline.handler.UnsatisfiedRequirement: ('No provider found for type', typing.Annotated[__main__.Str, 'metadata'])
pl.compute(AStr) |
Disallowing this would mean that annotated types can never be used with Sciline. This may be too limiting. |
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently using
typing.Annotated
as parameters or for type hints in providers leads to mostly cryptic exceptions. One could consider supporting it, but it would require using__annotations__
(or inspect.get_annotations in newer Python) instead oftyping.get_type_hints
.One could probably get this too work, but I fear it may be more brittle. Therefore, we should carefully consider whether support for
Annotated
is desirable. If not, we should attempt to raise clearer error messages.The text was updated successfully, but these errors were encountered: