mCodingLLC / VideosSampleCode

Code from the mCoding sample videos
MIT License
978 stars 203 forks source link

Type hint question #1

Closed MicaelJarniac closed 3 years ago

MicaelJarniac commented 3 years ago

https://github.com/mCodingLLC/VideosSampleCode/blob/ca7369eab00919a43dfc06c1c31dc7f2c61c2d61/exponentiation_efficient.py#L8

Shouldn't the type hint for step_limit there be Optional[int] instead of just int?

John98Zakaria commented 3 years ago

I would say you scored your 1st pull request :D

mCodingLLC commented 3 years ago

Thanks for pointing this out! It is pretty common to use a default value of None to indicate the type hint is optional (you can see that get_type_hints still does this https://docs.python.org/3/library/typing.html#typing.get_type_hints). Apparently, a past version of PEP 484 allowed for this behavior, but the recommendation has since changed. https://docs.python.org/3/library/typing.html#typing.get_type_hints "A past version of this PEP allowed type checkers to assume an optional type when the default value is None,". GvR is also sponsoring a PEP to make the question mark stand for optional as well: https://www.python.org/dev/peps/pep-0645/, so the typing of optional things may change again in the future.

I had read this past pep and have been using this convention for a long time, but I suppose now is as good a time as ever to realize the pep has changed and so should I! No need for a PR, I will just fix it.