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

Cannot type check with from __future__ import annotations #329

Open
williamlw999-fb opened this issue Mar 29, 2022 · 0 comments · May be fixed by #333
Open

Cannot type check with from __future__ import annotations #329

williamlw999-fb opened this issue Mar 29, 2022 · 0 comments · May be fixed by #333
Assignees

Comments

@williamlw999-fb
Copy link

from __future__ import annotations turns type annotations into strings that can later be evaluated at runtime via typing.get_type_hints see PEP 563. This is problematic because TestSlide uses the following pattern to find the expected type:

    try:
        argspec = inspect.getfullargspec(template)
    except TypeError:
        return
    expected_type = argspec.annotations.get("return")

In this scenario, expected_type is a string when the expected type is Type (see _validate_argument_type() which only works if expected_type is a Type).

It seems like a potential solution is:

    try:
        hints = get_type_hints(template)
        expected_type = hints.get("return")
    except TypeError:
        return

Will continue testing (I am on python 3.8.6).

@williamlw999-fb williamlw999-fb self-assigned this Apr 19, 2022
@williamlw999-fb williamlw999-fb linked a pull request Apr 19, 2022 that will close this issue
4 tasks
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