| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
The Any return type is intentional here because Union return types are generally annoying to deal with. This is mentioned in https://github.com/python/typeshed/blob/master/CONTRIBUTING.md#conventions. |
Sorry, something went wrong.
|
I don't really agree with that as the user always has the option to cast or just ignore Union return types and having specific types is the purpose of stub files but sorry for the fuss if it's common convention. Then again, that convention is not followed consistently. There are e.g. signatures for next and sum in the same file that do have Union return types... |
Sorry, something went wrong.
There was a problem hiding this comment.
Please no. The Any was intentional. Otherwise mypy will prompt users for isinstance () checks even with n**2.
Sorry, something went wrong.
|
The union return types for next() and sum() are only overloads for special cases, and in most cases the union will disappear because the iterator item type and the default/start value type are the same. |
Sorry, something went wrong.
|
There's absolutely no requirement for isinstance. Other options the user has include:
|
Sorry, something went wrong.
|
All of those have the same problem as isinstance -- if you have working correct code, mypy gives you a false positive forcing you to make it uglier. While sometimes that's the right thing to do (e.g. a = []), usually we prefer false negatives over false positives, since false positives very quickly annoy users. Remember that mypy users are Python users first and foremost, not type system zealots. :-) |
Sorry, something went wrong.
|
By the way, mypy already special cases type checking of n**m for integers when m is a literal, and it can infer int / float as the type instead of Any. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
No description provided.