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

Replace typeguard with beartype #685

Merged
merged 5 commits into from
Jun 1, 2023
Merged

Conversation

fholger
Copy link
Collaborator

@fholger fholger commented Jun 1, 2023

As typeguard was found to be too slow for larger input files, this PR replaces it with beartype. beartype is significantly faster and can handle large inputs, however, it comes with a caveat in that it does not do full nested deep type checks, but instead does random sampling in such instances. As such, it can allow certain misuses of types to go undetected, but it will still detect a majority of typical type mistakes. It is most likely better to have beartype than have nothing now even if it ends up not being the final solution to the validation issue.

fholger added 4 commits June 1, 2023 10:17
This reverts commit 21c7e32.

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
typeguard was prohibitively slow on large inputs, beartype is
significantly faster. However, beartype comes with a caveat in that it
does not do deep nested type checks, but instead utilizes randomized
sampled testing. As such, this still allows certain misuses of types to
go undetected and may not be our final solution. However, in the
meantime we deem it is much better to have beartype than not have any
type checking taking place.

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might want to keep this kind of test so that we retain some control over what the error messages would actually look like. Point in case: The latest typeguard update changed the error message for union types to an incomprehensible multi-liner.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, beartype error messages are a bit randomized in the order of union types, so this test would need to be done a bit differently. I propose dropping it for now, and if we stick with beartype longer term, we can have a more detailed look into its error messages and add appropriate tests and improvements to them.

Signed-off-by: Holger Frydrych <holger.frydrych@tngtech.com>
@armintaenzertng armintaenzertng merged commit 5a6d4e3 into spdx:main Jun 1, 2023
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 this pull request may close these issues.

2 participants