We used to directly subclass int to implement our numeric types. Unfortunately that approach violated the Liskov substitution principle: replacing any arbitrary int with an instance of Uint could break the program.
Instead, our integer types are fully separate classes, and with that comes significant performance penalties.
Based on some quick experimentation on my part, we should be able to make our integer types inherit from int but convince mypy that they aren't actually subclasses of int by using a custom *.pyi file. This would give us the performance benefits of being an int subclass, but the stronger typing guarantees of our current approach.
We used to directly subclass
intto implement our numeric types. Unfortunately that approach violated the Liskov substitution principle: replacing any arbitraryintwith an instance ofUintcould break the program.Instead, our integer types are fully separate classes, and with that comes significant performance penalties.
Based on some quick experimentation on my part, we should be able to make our integer types inherit from
intbut convince mypy that they aren't actually subclasses ofintby using a custom*.pyifile. This would give us the performance benefits of being anintsubclass, but the stronger typing guarantees of our current approach.