17:57 For anyone wondering, we could use Tuple[int, ...]. This way, we annotate that the tuple should only contain integers, but it can be of any length, so we don't have to type exactly 3 ints.
@martonturbuk30603 жыл бұрын
Hi there, I came here to comment on this recent video, so I get a bigger chance of you reading this. I just wanted to thank you for all the work that you did put in these videos. I watched several of your longer videos (The Complete Python Course For Beginners for example) and they are really good. You helped a lot of people to learn, and gain knowledge, for free. Keep up the good work, and thank you.
@bencipherx3 жыл бұрын
@@techwithtim8893 is that ur WhatsApp number?
@UrBigSisKey2 жыл бұрын
That's thoughtful of you ... :)
@gaurishgangwar Жыл бұрын
I think Optional (at 14:10) means different than being an optional argument. Optional[bool] means that the argument can either be bool or None.
@piraloco586410 ай бұрын
Kind of, your explanation on the optional type is 100% true, but you can still use it to represent optional arguments, since it means that if you dont pass the argument the type checker will accept it.
@rabinadk19 ай бұрын
I was about to comment the same. Optional type is kind of confusing to most of the people. It just means additionally None.
@max.caimits3 жыл бұрын
From typing module docs: ❝Optional[X] is equivalent to X | None (or Union[X, None]). Note that this is not the same concept as an optional argument, which is one that has a default. An optional argument with a default does not require the Optional qualifier on its type annotation just because it is optional.❞
@GeorgeSanger Жыл бұрын
Add to add to this setting a argument to optional[bool] now mean that you can set output to None e.g. foo(None), now inside the function output will be None not False. And this wouldn't be caught by mypy. I do believe that part is incorrect, but very useful video otherwise
@garfield-pro Жыл бұрын
Thanks for explaining Union type which Tim missed out.
@paulzupan37322 жыл бұрын
According to the mypy documentation, an Iterable is anything that can be used in a for loop. A Sequence is anything that supports both len and __getitem__.
@larrystone6542 жыл бұрын
Your videos are so refreshingly clear! Question: If the typing library is used for the purpose of complaining about incorrect typing, why do you need to run the program through mypy instead of just running the python program and letting *it* complain?
@danielcrone95532 жыл бұрын
Thanks for the great explanation! It'd be also good to add how people generally indicate more library-specific types like df in pandas, class, numpy, path variables.
@PeceniJaguar2 жыл бұрын
You just use the Class that creates that object, e.g. `data: pd.DataFrame = pd.DataFrame(some_params_etc)`
@18something3 жыл бұрын
Optional is used more on the request payload validation, some of the fields are not always required. Not just to decorate an optional parameter
@18something3 жыл бұрын
Types shine on facilitating validation more than documentation. Feel like you need to couple this topic with pydantic as well
@cn-ml Жыл бұрын
You should probably use the NotRequired type then, instead of Optional.
@kingcrashplays3 жыл бұрын
This was the first thing I figured out due to the fact I come from a language like Java. Dynamically typed languages drive me insane, so whenever possible I always try to hint my variables with a specific type.
@cn-ml Жыл бұрын
Very informative, there are lots of things to add to this video, but you covered a great base. I would however like to see corrections on the Optional type, which you seem to have misunderstood a lot. It is definitely *NOT* used for optional parameters, but for parameters that can also be None (of course you could have optional default params: "name: Optional[int]=None"). Also in the Callable type optional does not provide default parameters, but Nullable params, but you still have to provide them in the call! If you want default params in callables, you should probably use the Protocol type.
@axis20102 жыл бұрын
As a few others have already commented, Tim’s explanation of Optional is incorrect. Optional means that the type can be None or the given type. e.g. Optional[bool] = False means that a user can pass in a value of type bool or None. I doubt Tim wants to allow the user to pass in None. The correct type should be bool = False
@rossli86212 жыл бұрын
Dude I just fell in love with your tutorial videos.
@kens_adventures2 жыл бұрын
Thanks for this crush course while I am in the middle of my take home coding challenge for my job application
@kaanb91922 жыл бұрын
this video was very helpful, since I saw some people use these type hints and annotations, I was wondering whether I am coding wrong. Turns out it is just for documentation...
@Mdroudian2 жыл бұрын
The tabnine is badass. Sourcery is also a great extension.
@loveafinni3 ай бұрын
Very helpful video. Thanks Tim.
@derekreed6798 Жыл бұрын
Wow, how complicated type hints are pre 3.9. Great video as I needed to know this stuff (so thanks for your time), but I'll upgrade my python before using typehints.
@meisherenow3 ай бұрын
Nicely explained in a short video.
@Saitama-ur3lq2 жыл бұрын
ah! the definitive edition of typescript for python is here lol
@shikharpathak85103 жыл бұрын
How amazing it is... Like there is always a lot to learn. Thanks for taking us along ❤️
@TechWithTim3 жыл бұрын
Thanks for watching!
@shikharpathak85103 жыл бұрын
Lots of love and gratitude❤️
@mohamedfarag9136 Жыл бұрын
Thank you very much for your explanation!
@alloutofafricanpolarbears3 жыл бұрын
Thanks for the info dump. I have just recently started using this.
@pic013 жыл бұрын
Thank you so much for this information, so helpful for me and everyone else
@sethutrun3 жыл бұрын
Love the python videos!! Thank you so much
@prueba-numero-uno3 жыл бұрын
It's amazing, I need to find how to use Type Hints on Django. When I use values like Dates, Email, Passwords, etc...
@soupnoodles3 жыл бұрын
Hey, thank you so much! Pretty helpful video, keep making these man :)
@MsOfficeLearning3 жыл бұрын
Thank for the best tutorial sir.
@pianopianist57093 жыл бұрын
I was watching your shorts video when I got this notification!
@pratyushbehere35802 жыл бұрын
Thanks, short and useful.
@Absolotle3 жыл бұрын
Thank you! I didn't know that you could specify and test types like that. I noticed that when you tested the set as a sequence, (at 16:45) your set caontained ints instead of strings (you specified a sequence of str). Maybe that's the reason for the error and not the fact that you can't index a set?
@Absolotle3 жыл бұрын
ok, I tried and and, yes - also a set of strings will produce an error
@Zoronoa012 жыл бұрын
Thank you Tim!
@miguelvasquez98492 жыл бұрын
Should i use Sequence[str] instead of List[str]? For your example [‘a’,’b’]
@WolfsInk Жыл бұрын
And to think I'd just finished revamping my project creator code from the last video from you I'd watch... XD I wonder how well this would interact with pylint.
@gerreyal2 жыл бұрын
Thanks Tim for the very usefull video.
@tomgreg2008 Жыл бұрын
Great video, thanks!
@reza-iq5df3 ай бұрын
Great video thanks
@constantinci2 жыл бұрын
What about declaring types of custom classes as methods/constructors parameters?
@gameacer1113 жыл бұрын
Great info Tim! Thanks! Love the videos
@InglesConConfianza Жыл бұрын
GREAT VIDEO!
@CaptainBravo87 Жыл бұрын
Great video!
@will2see3 жыл бұрын
Hi Tim, what keyboard are you using? I like the sound it makes ;-)
@RanjithKumar-jo7xf Жыл бұрын
This is really awesome ❤️❣️
@dominikwodarczyk67143 жыл бұрын
Also Union is pretty useful
@sushantgupta4757 Жыл бұрын
Thank you so much
@MikeEldridge-e7l3 ай бұрын
Is there a way to enforce type annotations? Like to make sure developers are type annotating their code?
@jleonardolemos2 жыл бұрын
great video, thanks!!!!
@squidproxy1362 жыл бұрын
amazing, thanks
@John_Shi3052 жыл бұрын
非常感谢, thank you
@ghyslainhubert139 Жыл бұрын
In my case, VS Code/Python 3.11.5, just starting the video (5:05), int x = 1 already causes an error "Expression value is unused" Pylance. If I enter x: int = "Hi", "Hi" is underlined as an error : Expression of type "Literal['Hi']" cannot be assigned to declared type "int", so : int causes an error. Like x: str = 1, I get a Expression of type "Literal[1]" cannot be assigned to declared type "str" "Literal[1]" is incompatible with "str"Pylance.
@gustavopoa3 жыл бұрын
Thanks Tim
@taharatamin34343 жыл бұрын
Tim, create a tutorial on docker if possible
@garfield-pro Жыл бұрын
Hey Tim, How do we hint the type of *args and **kwargs?
@raziyehnikookolah6107 Жыл бұрын
very useful
@miloventimiglia8547 Жыл бұрын
Isn't the case that if you find yourself needing static feature, you should opt in for Java? Or a more advance language? Python leads to a lot of overheads whereas in Java everything is already built in
@HubertRozmarynowski2 жыл бұрын
Thanks for the video, Tim. How would you type a list that can store both float and int types?
@roshanyadav44592 жыл бұрын
List[int,float]
@OmidAtaollahiАй бұрын
great. tnx
@nsomething2100 Жыл бұрын
Hi there, question about the type "tuple" that you mention at 17:05 - What if there is a tuple with a large length (thousands of elements) - do we still need to specify the expected type at each position of the Tuple ?
@pD5V0DdsaoVhq Жыл бұрын
Yes you do. But tuples are generally used in places like returning multiple values from a function. If you need 1000 elements, you should have used a list
@andresyesidmorenovilla78882 жыл бұрын
Hi tim, excellent video! thank you so much. I have a question, how would one go about typing a variable which is a dictionary, whose keys are all strings but whose values' types may be different (i.e int, float, bool, etc)?
@cn-ml Жыл бұрын
A bit late, but for people who are seeing this today: Dict[str, int | float | bool | etc]. Just use a Union of all types as a value. I personally prefer TypedDict to assign types for specific keys.
@sanjaykrish87192 жыл бұрын
Thanks!
@TechWithTim2 жыл бұрын
Appreciate you !
@splendorman79222 жыл бұрын
x: list[list[int]] = [[2,3],[1,6]] works for me. is it because of version difference? Tried it on v3.9
@prashantlawhatre70072 жыл бұрын
14:23 So, Optional[bool] = Union[bool,None] and not because it has default value.
@fivefournino3 жыл бұрын
How would one type hint for objects you pull in from other packages? (Dataframe in-np array out, list in-praw out, etc)
@BiologyIsHot3 жыл бұрын
Import and then put the class name ie var1: pd.DataFrame
@spinetticoАй бұрын
cristal clear
@lt_academy2 жыл бұрын
well done )
@ChrisLeftBlank9 ай бұрын
12:30 But i thought at the start they've said "If you are looking to replace long string with easy command THIS IS NOT THAT VIDEO ...", but now it kind of is. ?
@umeshlab9873 жыл бұрын
What software do you use for thumbnails
@tcgvsocg14583 жыл бұрын
Can you do a video on "make a platformer game in python 2021" or beat them all Thx a lot
@nunezkant Жыл бұрын
What about numpy arrays ?
@freakpandor8 ай бұрын
What if an object is a parameter?
@snippletrap2 жыл бұрын
pyright reports type errors in your editor or IDE, so you don't need to run mypy
@johnsmith-fk7fw3 жыл бұрын
i make it a point to make my code as hard as possible to read, like a puzzle. i call it 'davinci code' 😎
@mback120008 ай бұрын
So whats the usefulness of type hinting - compared to just comments - if you're not using an analysis tool?
@StepwaveMusic3 күн бұрын
Making your code readable If you don't understand how, open up a big Python project without type annotations and try to understand the code. You'll quickly figure out how inconvenient it is to not know the types of variables and function parameters.
@mback120003 күн бұрын
@@StepwaveMusic Thanks. I also since discovered (learned) that may other libraries can use type hinting. For example, I've been working in FastAPI, and it draws a lot of info from type hints including automating documentation.
@StepwaveMusic3 күн бұрын
@@mback12000 the typing library is a standard library, so indeed, it is interoperable with Python. This is the case with most libraries, although it depends.
@iluvsyphonfilter3 жыл бұрын
Hey Tim yesterday I was working on a Flask project and I noticed in the terminal that it made a GET request to a route from another project and of course it got a 404 because that route don't exist in the new project. I got scared and don't know what it could be, do you think someone got into my localhost? The IP address from the GET request was from my localhost.
@iluvsyphonfilter3 жыл бұрын
@@techwithtim8893 Nevermind, I think that was caused by something related to telemetry in the browser or something like that, anyways now I'm keeping the resource monitor and task manager opened on the side to see if I catch something strange in my network.
@bencipherx3 жыл бұрын
I lost a German job interview cos of type hinting, no more is that happening again 🦁
@bencipherx3 жыл бұрын
@Anne-[S]EX-Vlog Go to My Channel yes , it's type will be the class provided its imported or implemented in the same module
@haohuynhnhat38813 жыл бұрын
you can do list[bla, bla] in python >= 3.9, and in 5 years the List from typing.List will be deprecated
@DrDeuteron2 жыл бұрын
On tuple type (circa 17:40), what if my tuple is 10,000 ints? Do I need to code: x: Tuple[int, int, ....10000 times...int]? Seems Akward
@ONLYUSEmyTOILET Жыл бұрын
You could be specific and type it as x: tuple[(int,) * 10000] or just type it with arbitrary length as tuple[int, ...]
@murphygreen84843 жыл бұрын
Date types?
@محسن-ه1ه1ث3 жыл бұрын
how should we insert persian in kivy
@anugrahtriramadhan93003 жыл бұрын
How about iterable?
@itaydvash3 жыл бұрын
What about objects I created?
@uKaigo3 жыл бұрын
Isn't the Optional type used only when None can be passed? AFAIK when you have an have an optional parameter you shouldn't type it with Optional unless it accepts None Also Optional[T] is the same as Union[T, None], implying this
@ignis29823 жыл бұрын
Yes, but that only applies if you type hint return types.
@uKaigo3 жыл бұрын
@@ignis2982 oh, I thought it applied to parameters too, thanks
@this-is-bioman2 жыл бұрын
This is an excellent presentation with nice large and readable font, dark background and timestamps! Python is by far the most stupid language LOL By design dynamically typed and without access modifiers, but yet people demand these features so they added type hints and use underscores for private members. How can you not love this illogical design decisions? 🤣🤣🤣
@rajveer.singh-code4 ай бұрын
Annotated?
@paschalokafor9043 Жыл бұрын
@16.47 minutes you should have tried a set of strings not numbers.
@joseflat3 жыл бұрын
Anyone knows, how would I typehint , when I return an object of some of my classes?
@nyscire8773 жыл бұрын
Just typehint your class name. For example, if you namedyour class "Foo" you would do something like that: def func(parameter: Any) -> Foo
@BRLN13 жыл бұрын
You should have waited with this video until python 3.10 got published in a few weeks! However most stuff you present here is even with python 3.9 already deprecated!
@ahmedyousif47823 жыл бұрын
The only time that I used types in python is when dealing with data classes
@WillsonMock2 жыл бұрын
Does anyone know how to use a custom class definition as a type?
@pD5V0DdsaoVhq Жыл бұрын
The class name itself is a valid type.
@apnagamer613 жыл бұрын
1st comments
@ahmedyousif47823 жыл бұрын
ALGOEXPERT SHUT UP I DON'T WANT TO BE A SOFTWARE ENGINEER AT GOOGLE
@sujeewarathnaweera3 жыл бұрын
i got the ad in the vid before
@iddo-ba3 жыл бұрын
Hi
@pkavenger99902 жыл бұрын
16:51 I think it gave an error because you specified Sequence [str] but you put "int" in the function's parameter instead of a string.
@SenselessTalk3 жыл бұрын
First
@pianopianist57093 жыл бұрын
Yes!
@binaprajapati77093 жыл бұрын
Can we get some rust pleaseeee 🥺🥺
@user-jf4wc7tf9v3 жыл бұрын
NICE VIDEO!! Very engaging from the beginning to the END. Nevertheless Business and investment are the best way to make money irrespective of which party make it to the oval office.
@jimmys.fuller36593 жыл бұрын
Absolutely right, I got 70% of my total portfolio in crypto and I have been making good profits.
@rosalinda19653 жыл бұрын
I wanted to invest more in crypto, but the fluctuations in crypto value discouraged me into dumping.
@Flow.Monkam3 жыл бұрын
@@rosalinda1965 That won't bother you if you trade with a professional like Mr Nicholas howard.
@anitapearl27063 жыл бұрын
Wow 😮I’m just shocked you mentioned and recommended Mr. Nicholas howard I thought people don’t know him, he is really awesome.
@Flow.Monkam3 жыл бұрын
@@anitapearl2706 Yeah I know him, who doesn't know Mr Nicholas howard of (HSBC SECURITY (USA) INC).
@hanyanglee90182 жыл бұрын
Guys, rename this language as MyTython, or at least Tython.
@PhongNguyen-jd3fw3 жыл бұрын
So this is typescript in python 😂
@TechWithTim3 жыл бұрын
lol ya kinda feels like it
@BenEgeYouTube3 жыл бұрын
Cu
@kaiobatistaalmeida3 жыл бұрын
Cu means ass in portuguese, so it's kind of weird seeing it randomly
@Sciencedoneright3 жыл бұрын
@@kaiobatistaalmeida oh lol
@imahumanbeing613 жыл бұрын
m
@Sciencedoneright3 жыл бұрын
@@imahumanbeing61 lmao
@flaskblog30093 жыл бұрын
cu ou seios?
@maqdala Жыл бұрын
What font is that? What an L!
@krtirtho3 жыл бұрын
"Python typings don't enforce what type should be passed/used. It's just for documentation purposes" *In other words, it's useless*
@jigsaw22533 жыл бұрын
No it’s not you dump
@pablodm93 жыл бұрын
The average junior coder agrees 👍
@juanbetancourt51063 жыл бұрын
the main purpose is to get the code easier to read in big projects.
@BRLN13 жыл бұрын
shot shoveling ... beautiful
@krtirtho3 жыл бұрын
@@juanbetancourt5106 You really think Python is hard to read? Then reading Java is like reading machine code