-
Notifications
You must be signed in to change notification settings - Fork 83
More typing and mypy warnings, non-null user email #1860
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
Conversation
This mostly just introduces type annotations, there's a couple of instances of type narrowing and adding TypedDicts
88f9594 to
5602beb
Compare
5602beb to
21b1852
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I've made a lot of notes of "things that we should now tidy up" but those are for the future.
Also good to see a (at least second, maybe third?) actual bug caught by mypy.
| """ | ||
| if self.capacity_max is None: | ||
| return float("inf") | ||
| return sys.maxsize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using float("inf") as a sentinel, we shouldn't use an actual number here. float should work instead of int, but maybe create a new class if it upsets mypy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the logic in that - using float means that this function (and a bunch of stuff that calls it) has to use float | int everywhere, which is gross given it never returns "actual" floats. The place that actually checks for infinite capacity uses a large integer anyway:
| {%- if rem < 999999 %}{# Infinity check #} |
I think returning None for "no limit" would probably be cleanest, or some custom class as you say - but I wanted to avoid making too many logic changes and this seemed to me like it served the same purpose with mimimal changes required...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh ugh, I'd forgotten about that. I agree using floats is pretty icky, because it includes values (including infinity) where n - 1 == n, but my hope was it would allow us to continue as before. If we need to type it properly, I think an Infinity or Unlimited sentinel would be best, and could be checked in the template too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think int | Literal[math.inf] should work, although I don't know if mypy actually supports doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, no, that's illegal:
Literal may be parameterized with literal int, str, bytes, and bool objects, instances of enum.Enum subclasses, and None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah :( python/typing#1160
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/emfcamp/Website/tree/add-unlimited-type should fix this
Added a mark_transfer_paid cli command. Happy to remove if we don't want it, it's just useful for testing
Made
User.emailnon-nullable.Enabled & fixed more mypy warnings:
disallow_any_generics: e.g.dict->dict[str, int]disallow_incomplete_defs: if any signatures is partially typed, requires that it's fully typedwarn_return_any: warns if returningAnyfrom a function with a return typestrict_equality: didn't have to fix anything, but stops int/float str/bytes comparison with ==no_implicit_reexport: catches places where things are imported from a reexportMore progress towards #1855