More typing and mypy warnings, non-null user email#1860
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
| """ | ||
| if self.capacity_max is None: | ||
| return float("inf") | ||
| return sys.maxsize |
There was a problem hiding this comment.
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.
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:
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.
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.
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.
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.
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