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

Enforce types during tests #2546

Open
Tracked by #765
timobrembeck opened this issue Nov 11, 2023 · 2 comments
Open
Tracked by #765

Enforce types during tests #2546

timobrembeck opened this issue Nov 11, 2023 · 2 comments
Labels
💡 feature New feature or request ⁉️ prio: low Not urgent, can be resolved in the distant future. 😱 effort: high Big change, which requires >12h
Milestone

Comments

@timobrembeck
Copy link
Member

Motivation

At the moment, types are only checked statically via mypy. mypy does not execute the code, but just analyze it. It would be cool to check the types during the tests and make sure that all variables really have the expected types during runtime.

Proposed Solution

Not sure how we could achieve this, one possibility is the library strongtyping which provides a decorator @match_typing which throws an exception if a function call does not match its type annotations.

However, adding this to every function in the entire code base seems like a lot of overhead. Maybe we could achieve this by patching this dynamically just before the tests are run? (Either via monkeypatching or via a stupid regex-replacement of def occurrences...)

Alternatives

Rely on the current mypy checking

@timobrembeck timobrembeck added 💡 feature New feature or request ⁉️ prio: low Not urgent, can be resolved in the distant future. 😱 effort: high Big change, which requires >12h labels Nov 11, 2023
@timobrembeck timobrembeck added this to the Backlog milestone Nov 11, 2023
@timobrembeck timobrembeck mentioned this issue Nov 11, 2023
33 tasks
@david-venhoff
Copy link
Member

This might also be useful, even though it does not exactly what we want: https://mypy.readthedocs.io/en/stable/stubtest.html

@timobrembeck
Copy link
Member Author

This might also be useful, even though it does not exactly what we want: https://mypy.readthedocs.io/en/stable/stubtest.html

Good point! This is also what I used for the initial baseline of the types, but it required a lot of manual adjusting, would probably complicated to integrate into an automated workflow. But yes, we should investigate this when tackling this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💡 feature New feature or request ⁉️ prio: low Not urgent, can be resolved in the distant future. 😱 effort: high Big change, which requires >12h
Projects
None yet
Development

No branches or pull requests

2 participants