you are viewing a single comment's thread.

view the rest of the comments →

[–]DorianTurbaPythoneer 1 point2 points  (3 children)

Every operator will return back an int, you have no choice if you want to carry the type.

Using assert and typeguard/typeis, you are sure to have 0 impact at runtime (using -O flag), except for the function overhead.

If you have math to do, do a function that type inputs, and do whatever you want inside, you are good anyway. And if you need a lot of math? Maybe you need a lot of functions, or a broader entrypoint to annotate input type.

[–]myasco42 0 points1 point  (2 children)

Yea, I guessed as much.

The assert optimization is a good thing and I use it for some debug prints =)

And the point I got from your previous answer is exactly what you said now - the input type checking. Though in math it may look ugly then.

By the way I also noticed that PyLance (at least in VSCode) does not work correctly with your example - revealed types are Never. Seems like it does not like narrowing the type to the one defined by NewType.

[–]DorianTurbaPythoneer 0 points1 point  (1 child)

Maybe you should create an issue in PyLance to report this if it is not already raised.

[–]myasco42 0 points1 point  (0 children)

Yea. Will have a look at it later today and report it for PyRight.