Skip to content

Conversation

@wlcx
Copy link
Member

@wlcx wlcx commented Sep 15, 2025

Added a mark_transfer_paid cli command. Happy to remove if we don't want it, it's just useful for testing

Made User.email non-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 typed
  • warn_return_any: warns if returning Any from a function with a return type
  • strict_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 reexport

More progress towards #1855

This mostly just introduces type annotations, there's a couple of
instances of type narrowing and adding TypedDicts
@wlcx wlcx force-pushed the more-typing-and-mypy-warnings branch from 88f9594 to 5602beb Compare September 15, 2025 14:56
@wlcx wlcx force-pushed the more-typing-and-mypy-warnings branch from 5602beb to 21b1852 Compare September 15, 2025 15:00
Copy link
Member

@marksteward marksteward left a 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
Copy link
Member

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.

Copy link
Member Author

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...

Copy link
Member

@marksteward marksteward Sep 18, 2025

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.

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@marksteward marksteward merged commit 50e1ffe into main Oct 18, 2025
4 checks passed
@marksteward marksteward deleted the more-typing-and-mypy-warnings branch October 18, 2025 23:31
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.

3 participants