Тёмный

python TypeGuard (PEP 647) (intermediate) anthony explains  

anthonywritescode
Подписаться 42 тыс.
Просмотров 5 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 20   
@luck3949
@luck3949 2 года назад
Wow, now I don't have to use C++ to ponder at template typing mismatch errors, now I can do it with Python!
@ChrisBNisbet
@ChrisBNisbet 2 года назад
Anthony: "What!?" That's what I find myself saying way more often than I'd like.
@tannerbobanner9453
@tannerbobanner9453 7 месяцев назад
I know this is an old video, but for those watching: instead of binding T to type, type[T] should be used as the parameter type.
@sadhlife
@sadhlife 2 года назад
i suppose you can still do `bound=type` for the TypeVar there, it's just like `bound=object` but accepts any class instead of any object.
@DavidDellsperger
@DavidDellsperger 2 года назад
Anthony did editing? Impressive
@anthonywritescode
@anthonywritescode 2 года назад
just a simple cut!
@sadhlife
@sadhlife 2 года назад
consider this case for the negative case: ``` def is_zero(x: int | None) -> TypeGuard[int]: return x == 0 def foo(x: int | None) -> None: if is_zero(x): print("got zero") else: reveal_type(x) # int | None ```
@anthonywritescode
@anthonywritescode 2 года назад
yeah an imprecise narrowing makes sense
@RoyAAD
@RoyAAD 3 месяца назад
@4:40 you say this is a variance issue. Do you have a video that explains more about it?
@OrCarmi
@OrCarmi 2 года назад
I see that "fumble" not as a failure of you Anthony, but as a testament to how clumsy and unintuitive python typing becomes at higher levels
@aldrickdev
@aldrickdev 2 года назад
when i try to import TypeGuard mypy tells me that its not a valid type. I tried importing it from the typing module and the typing_extensions module and I still get the same error.
@anthonywritescode
@anthonywritescode 2 года назад
you'll need a sufficiently new version of mypy (and if you're importing it from `typing` you'll need to make sure you're targetting a new enough python version)
@marsma18
@marsma18 2 года назад
Oh. I just want to write comment that this is not your style to let unclear stuff exist and then i see this addition. You met my expectation :)
@xaro6132
@xaro6132 2 года назад
Why did you used `object` instead of `typing.Any` ? is there any practical difference?
@xan1716
@xan1716 2 года назад
If I'm correct, object would mean a nondescript input param which you would have to narrow down in the function body, whereas Any is an escape hatch to tell the type checker that all bets are off, do not type check this, or anything that this touches
@kevinkalanda9946
@kevinkalanda9946 2 года назад
He has another video about this: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ATS9MAo2Mjc.html
@JohnZakaria
@JohnZakaria 2 года назад
He has a video on that
@JohnZakaria
@JohnZakaria 2 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-ATS9MAo2Mjc.html
@akshaymestry7503
@akshaymestry7503 2 года назад
even your failures are graceful 😅😇😂
@alexeiguirik9463
@alexeiguirik9463 2 года назад
Anthony: "This is a disaster..." Sometimes I think that about type hints in Python in general.
Далее
python descriptors! (advanced) anthony explains #519
19:04
skibidi toilet 77 (part 4)
05:20
Просмотров 11 млн
Python 3.12 Generic Types Explained
18:27
Просмотров 62 тыс.
python Generics (intermediate) anthony explains #430
13:43
python 3.12 was ALMOST javascript
9:32
Просмотров 56 тыс.