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

Breaks under __future__.annotations #104

Open
jtrakk opened this issue Jun 16, 2019 · 0 comments · May be fixed by #114
Open

Breaks under __future__.annotations #104

jtrakk opened this issue Jun 16, 2019 · 0 comments · May be fixed by #114

Comments

@jtrakk
Copy link

jtrakk commented Jun 16, 2019

Annotations are becoming string-valued by default in a future version. This feature is accessible in Python 3.7 with from __future__ import annotations.

This breaks the current implementation of multipledispatch.dispatch():

from __future__ import annotations

import multipledispatch


@multipledispatch.dispatch()
def func(x):
    raise NotImplementedError(x)


@multipledispatch.dispatch()
def func(x: int):
    return f"x {x} int"


print(func(1))

Traceback (most recent call last):
  File "/home/user/tmp/single.py", line 11, in <module>
    @multipledispatch.dispatch()
  File "/home/user/.local/pipx/venvs/ipython/lib/python3.7/site-packages/multipledispatch/core.py", line 68, in _
    dispatcher.add(types, func)
  File "/home/user/.local/pipx/venvs/ipython/lib/python3.7/site-packages/multipledispatch/dispatcher.py", line 225, in add
    (typ, str_sig, self.name))
TypeError: Tried to dispatch on non-type: int
In signature: <int>
In function: func

The solution that functools.singledispatch uses is to call typing.get_type_hints() to evaluate the hint strings.

@JacobHayes JacobHayes linked a pull request Apr 18, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant