Hacker News new | ask | show | jobs
by vsnf 938 days ago
I got frustrated on the very first example (Basic 1: Any) because I didn't realize that the typings library wasn't imported by default. Maybe I should have known better, but it definitely got me.
6 comments

Well, that is realistic :D I agree it is a pain point with python typing, but it is something good to learn in this activity and remember honestly!
I made the same error. OP, maybe instead of only giving the option to see the solution, also give the option to just see a hint?
Also, a "Next example" button would be great.
I definitely considered adding hints. But it's gonna be a ton of work to create proper hints and I'm yet to prioritize it.
I assume that's intentional so you learn when it's required. From Python.org:

"all functions without a return type or parameter types will implicitly default to using Any"

I passed the test with `object` :)
I literally didn't change the code, so there was no annotation at all, and it still passed.
I thought that one was an example where you don't have to do anything.

I just went back to check and I saw that you are supposed to make some changes, which are shown in the solution, even though they are unnecessary to pass the tests.

The "any" challenge is special, it's the only one where you don't need to make any changes :)
I opened an issue asking them to add `from typing import *` to the boilerplate.
you aren't wrong , any is available in python 3.10 . There is no need to import typing.Any
Those are completely different.

any - https://docs.python.org/3/library/functions.html#any - Return True if any element of the iterable is true.

Any - A special kind of type is Any. A static type checker will treat every type as being compatible with Any and Any as being compatible with every type.

Let's not forget ANY as in "from unittest.mock import ANY".
Whoops, I always thought I can use any as type. Damn my bad
I still think callable, and iter should be usable this way.

any(), probably not. The semantic is too different.

But having to import Callable while callable is a built-in is a missed opportunity.

I don't miss Union, Optional and List.

what? `any` - the builtin function[0] is part of python since the dawn of time but from what I know is not usable as a type annotation, and `typing.Any` should be used (and imported explicitly)

[0] https://docs.python.org/3/library/functions.html#any