python Generics (intermediate) anthony explains #430

python Generics (intermediate) anthony explains #430

anthonywritescode

2 года назад

15,017 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Veloz
Veloz - 27.04.2023 00:05

Is there any value in making a method generic that doesn't take any parameters, but could return a variety of things?

Ответить
BYte __
BYte __ - 24.08.2022 00:04

If I remember correctly, you don't need necessarily to type annotate the constructor if you say so: my_object = FDict[str, int]()

In this case, it makes no sense but still, you can. BTW good video, and a very interesting topic

Ответить
jbrnds
jbrnds - 17.05.2022 09:38

I have a question for you, @anthonywritescode. I am in a continuous merge request review discussion back and forth with others regarding the use of `NoReturn` vs `None` for the return of a function or method that does not returns anything. Can you please shine your light on it? Docs state then the `NoReturn` is used for functions that are not expected to return anything; eg. an Exception raising function.

Ответить
Gabriel Mota
Gabriel Mota - 16.05.2022 22:54

Awesome, a video about covariant/contravariant would be nice

Ответить
Kirill Ratkin
Kirill Ratkin - 16.05.2022 22:23

Cool. Python becomes ... Haskell ;). Anthony, this is not fair. ;) Tell us about covariant and countervariant. ;)

Ответить
Akrylic
Akrylic - 16.05.2022 19:45

This is awesome

Ответить
Dhruva Kashyap
Dhruva Kashyap - 16.05.2022 19:16

I remember my professor talking about covariate and contravariant types and all I remember is that "a bag of apples is not a bag of fruits"??

Ответить
Tushar Sadhwani
Tushar Sadhwani - 16.05.2022 18:57

waiting for the 1 hour variance wideo *grabs popcorn

Ответить
Tushar Sadhwani
Tushar Sadhwani - 16.05.2022 18:55

random trivia I learned recently: to make a generic protocol class, you can do:

```
class C(Protocol, Generic[T]): ...
```

which is a bit much, so there's a shorthand:

```
class C(Protocol[T]): ...
```

Ответить
David Dellsperger
David Dellsperger - 16.05.2022 18:01

/me misreads title as "python Geriatrics (intermediate)"...don't mind me

Ответить