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 type hints #60

Open
jonathanmaw opened this issue Mar 13, 2023 · 2 comments
Open

Enforce type hints #60

jonathanmaw opened this issue Mar 13, 2023 · 2 comments

Comments

@jonathanmaw
Copy link
Contributor

jonathanmaw commented Mar 13, 2023

While working on this, I have been frustrated by model diffs producing unexpected results because they have tried to compare a list of E-mail addresses with a tuple of E-mail addresses, and finding that they differ.

There are, broadly, 2 possible ways to fix this:

  1. Use mypy, a static type checker for python, to check that we're using appropriate types.
  2. Use type_enforced (https://github.com/connor-makowski/type_enforced) to decorate the User and Group class (and hope that it's compatible with the dataclasses decorator)
@jonathanmaw jonathanmaw changed the title use mypy to enforce type decorators Enforce type hints Mar 13, 2023
@jonathanmaw
Copy link
Contributor Author

I don't think type_enforced will work. While trying to use it, its type enforcer complains about how dataclasses implements generating default values, i.e.

TypeError: (User.__init__): Type mismatch for typed variable `email`. Expected one of the following `[tuple[str]]` but got `<class 'dataclasses._HAS_DEFAULT_FACTORY_CLASS'>` instead.

@jonathanmaw
Copy link
Contributor Author

Next option: See if mypy complains.

If that doesn't work: give up and just add a __post_init() method to the User and Group classes which tries to convert the emails and groups fields into tuples.

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

No branches or pull requests

1 participant