Python tricks: Type hints and static type checking

  Рет қаралды 21,441

Sebastiaan Mathôt

Sebastiaan Mathôt

Күн бұрын

Пікірлер: 56
@zakariaabderrahmanesadelao3048
@zakariaabderrahmanesadelao3048 2 жыл бұрын
that is the clearest and simplest explanation for type hints. thank you man.
@austinhaider105
@austinhaider105 6 жыл бұрын
I've learned everything I know about Python from KZbin and your videos are some of the best I've come across. I appreciate the amount of detail you go into about every topic; keep it up!
6 жыл бұрын
Thank you!
@francescofaccia
@francescofaccia 3 жыл бұрын
Good job Seb. Very well explained. Clear and synthetic!
@arachnid83
@arachnid83 5 жыл бұрын
Thanks for explaining this. Your explanation was very deep and clear. I was a little perplexed with this concept.
@david-oj2je
@david-oj2je 2 жыл бұрын
Thanks I absolutely love your videos
@raspreetsingh5542
@raspreetsingh5542 4 жыл бұрын
An amazing explanation dude, I was having some difficulty understanding the callable type hints but you did such an amazing job of ELI5ing it. Thanks a lot :) and keep the great content coming
@nelsonmacy1010
@nelsonmacy1010 4 жыл бұрын
Very clear and to the point. Appreciate
@xmandeng
@xmandeng 3 жыл бұрын
Really helpful overview. Thanks!
@pyadaaah9866
@pyadaaah9866 4 жыл бұрын
Nice video - thank you! Maybe you also could be interested in Pyadaaah, which provides runtime (!) type AND range checking?
@barulli87
@barulli87 4 жыл бұрын
everything is clearly explained! cheers!
@mivoe99
@mivoe99 4 жыл бұрын
This is a great video on the topic
@debSha007
@debSha007 4 жыл бұрын
Hi, For the first program I'm getting "Incompatible return value type (got "None", expected "int")" how to deal with it ?
@javierbosch1338
@javierbosch1338 7 жыл бұрын
I'd love to get a list of your atom Python Packages that you are using. the REPL, autocomplete , etc. packages
7 жыл бұрын
If memory serves me, I was using magicpython, for correct syntax highlighting, and autocomplete-python for (obviously) autocompletion. The terminal that you see on the left isn't part of Atom though-it's a standalone Linux terminal!
@wolverinerazor
@wolverinerazor 6 жыл бұрын
which Linux distro do you use? btw, amazing videos. when will you become a trainer on pluralsight/ lynda etc?
@flyingsquirrel3271
@flyingsquirrel3271 6 жыл бұрын
Is None still always accepted by mypy? And if yes, why are they not using the "Optional" class from the typing module for that?
6 жыл бұрын
It seems they've changed this behavior (as default) as of MyPy 0.600, released last May. Now, None is no longer compatible with any type, but rather (as you say) you need explicitly allow None using the Optional type hint. An improvement in my opinion!
@thecodebear
@thecodebear 3 жыл бұрын
I really enjoyed it. Very usefull video . Thank you so much for this
@compucademy
@compucademy 4 жыл бұрын
Nice. Clear and helpful.
@wentaoqiu4072
@wentaoqiu4072 5 жыл бұрын
Your explanation is amazing, and your outfit is stunning..
@justchary
@justchary 5 жыл бұрын
Man, you good! Thanks for explanation.
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
PHP has real type hints. I was surprised to find out that Python’s interpreter ignores them.
@springinfialta106
@springinfialta106 7 жыл бұрын
Static Typing rules!
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
It does, but Python doesn't handle that too well.
@sudharsan4040
@sudharsan4040 5 жыл бұрын
Thanks for the informative video.
@RodrigoStuchi
@RodrigoStuchi 5 жыл бұрын
👏 👏 👏 👏, very nice explanations, thank you!!
@jeremyclark9697
@jeremyclark9697 4 жыл бұрын
Thank you!
@reydavid7300
@reydavid7300 5 жыл бұрын
Which code editor is that?
@RajveerSingh-yb6zq
@RajveerSingh-yb6zq 3 жыл бұрын
Except, Negative number have factorials :) And float have too... :)
@soldadopreciso
@soldadopreciso 5 жыл бұрын
interesting video, thanks pal, go ahead.
@lazypunk794
@lazypunk794 5 жыл бұрын
Anyone else getting an error in factorial function while doing mypy type checking. It says return type got "None" expected "int", which actually makes sense because we are returning NOne for a certain case when we have mentioned that return type is int. Why is that error not popping up for you? Seems mypy got some smarter updates since
@lazypunk794
@lazypunk794 5 жыл бұрын
And now passing "None" where "int" is expected gives error in mypy.
5 жыл бұрын
That's right. I believe that previous versions of MyPy (as I'm using in the video) always accepted None, whereas modern versions more sensibly don't. After all, int != None
@lazypunk794
@lazypunk794 5 жыл бұрын
@ this actually causes another issue. Now in your type hints, you cant use "int" as your return type for the factorial function since we return "None" when number = 0. you are forced to use "Any" as return type.
@Serotonindude
@Serotonindude 6 жыл бұрын
optional static typing... :D am i wrong, or is it like: 1) if static typing would have saved you... of course, you didn't use it 2) if i take my time to give proper type hints... why does the runtime not care at all? i may optionally type check it with another program... i don't know... feels like do it right all the time or just leave it
6 жыл бұрын
I agree that the current implementation of static typing is a bit half-baked. But I wouldn't be surprised if future versions of Python will allow you to enforce the type hints, and that could be very useful in some cases. (I have no inside information to support this, but just based on common sense I suspect that the Python devs will move in that direction.)
@ambig1
@ambig1 6 жыл бұрын
what webcam do u use? it is so good....
6 жыл бұрын
+Gajendra Ambi I'm using a Canon 750D, which is a decent photo camera.
@AliHasan-xh8in
@AliHasan-xh8in 4 жыл бұрын
Thx for the tutorial
@oleholgerson3416
@oleholgerson3416 6 жыл бұрын
what about classes? how can you check for those?
6 жыл бұрын
That's actually really straightforward, because you can directly specify the name of any class in a type hint, as you can see below. It only becomes more complex if you want to specify details about the class, such as in the case of List[int], which specifies not only that you expect a list, but also that it should be a list of ints. class MyClass: pass def print_myclass(v: MyClass): print(type(v)) myobject = MyClass() print_myclass(myobject)
@ukaszx4072
@ukaszx4072 5 жыл бұрын
Hi, Can someone explain me why there is a this -1 in line "return i*factorial(i-1)". I tried without that -1 run my code and it fails, but why? And which part of this code knows to divide some value like 3 into 1x2x3?
5 жыл бұрын
This is a classic computer-science exercise. You can find more details about it here: python.cogsci.nl/basic/functions/#exercises
@johnmarquess7375
@johnmarquess7375 6 жыл бұрын
Useful. Thanks.
@deadc0de517
@deadc0de517 6 жыл бұрын
Isn't it proper to use Dict[Hashable,int] instead of Any as key?
6 жыл бұрын
That's an interesting question. Strictly, there's no difference, because the keys in a dict are by definition hashable. However, you could say that making this property of dicts explicit in a type hint makes code more readable. On the other hand, most people probably don't know what hashable means, so I would be inclined to say that it makes code less readable.
@ArjunPatel-gk9lq
@ArjunPatel-gk9lq 5 жыл бұрын
what compiler is this?
5 жыл бұрын
Since Python is an interpreted language, there's no compiler involved! (That term is generally reserved for programs that translated compiled languages like C to machine code.) But the editor that I'm using is Atom. And the static type checker is MyPy.
@ArjunPatel-gk9lq
@ArjunPatel-gk9lq 5 жыл бұрын
@ thank you! i have a lot to learn about python lol
@vineethgeorge7387
@vineethgeorge7387 4 жыл бұрын
bro i need this intro song loved it verymuch
@rafadydkiemmacha7543
@rafadydkiemmacha7543 4 жыл бұрын
Coming from PHP, type hints in Python are actually really disappointing. The fact that they require external arbitrary tool to do anything is just weird. But the fact that None always passes makes type hints in Python virtually useless in my book.
@asdf3568
@asdf3568 3 жыл бұрын
But it still returns None and doesn't complain
@valizeth4073
@valizeth4073 3 жыл бұрын
Dynamic typing is aids.
Python tricks: The for loop (for, continue, break, else)
13:16
Sebastiaan Mathôt
Рет қаралды 8 М.
Python tricks: All there is to know about Exceptions
18:12
Sebastiaan Mathôt
Рет қаралды 18 М.
Disrespect or Respect 💔❤️
00:27
Thiago Productions
Рет қаралды 36 МЛН
Who's spending her birthday with Harley Quinn on halloween?#Harley Quinn #joker
01:00
Harley Quinn with the Joker
Рет қаралды 21 МЛН
ROSÉ & Bruno Mars - APT. (Official Music Video)
02:54
ROSÉ
Рет қаралды 315 МЛН
Improving Python performance with multiprocessing | Python tricks
15:29
Sebastiaan Mathôt
Рет қаралды 9 М.
Carl Meyer - Type-checked Python in the real world - PyCon 2018
32:10
5 Reasons Why You Should Use Type Hints In Python
13:54
ArjanCodes
Рет қаралды 108 М.
Python tricks: Demystifying async, await, and asyncio
15:59
Sebastiaan Mathôt
Рет қаралды 94 М.
Type-Checking Python Programs With Type Hints and mypy
10:50
Real Python
Рет қаралды 48 М.
The Right Way To Return API Errors in .NET
10:40
Nick Chapsas
Рет қаралды 40 М.
Python's Type Annotations DON'T Do What You THINK They Do
8:10
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 590 М.
Python tricks: properties, staticmethods, and classmethods
12:39
Sebastiaan Mathôt
Рет қаралды 44 М.