Re:Show HN: Python-Type-Challenges, master Python typing wit...
by vsnf on Wednesday November 29, 2023 @05:23AM
(#38457677)
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.
[ Parent
| on HN ]
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by burning_hamster on Wednesday November 29, 2023 @05:26AM
(#38457708)
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?
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by burning_hamster on Wednesday November 29, 2023 @05:33AM
(#38457755)
Also, a "Next example" button would be great.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by laike9m on Wednesday November 29, 2023 @11:47AM
(#38461746)
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.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by v3ss0n on Wednesday November 29, 2023 @05:41AM
(#38457801)
you aren't wrong , any is available in python 3.10 . There is no need to import typing.Any
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by karamanolev on Wednesday November 29, 2023 @06:03AM
(#38457951)
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.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by nicolaslem on Wednesday November 29, 2023 @06:06AM
(#38457976)
Let's not forget ANY as in "from unittest.mock import ANY".
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by v3ss0n on Thursday November 30, 2023 @11:37AM
(#38475571)
Whoops, I always thought I can use any as type. Damn my bad
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by BiteCode_dev on Wednesday November 29, 2023 @06:16AM
(#38458046)
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.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by _ZeD_ on Wednesday November 29, 2023 @06:08AM
(#38457991)
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)
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by roland35 on Wednesday November 29, 2023 @10:17AM
(#38460396)
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!
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by hsfzxjy on Wednesday November 29, 2023 @10:22AM
(#38460488)
I passed the test with `object` :)
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by quietbritishjim on Wednesday November 29, 2023 @11:08AM
(#38461180)
I literally didn't change the code, so there was no annotation at all, and it still passed.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by crunchbang-excl on Wednesday November 29, 2023 @11:20AM
(#38461369)
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.
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by laike9m on Wednesday November 29, 2023 @11:45AM
(#38461714)
The "any" challenge is special, it's the only one where you don't need to make any changes :)
Re:Show HN: Python-Type-Challenges, master Python typing wit...
by georgehotelling on Wednesday November 29, 2023 @10:53AM
(#38460984)
I opened an issue asking them to add `from typing import *` to the boilerplate.