Function Overloading For Python Developers (Singledispatch)

preview_player
Показать описание
In this tutorial I will be showing you how you can perform function overloading in Python using singledispatch from functools.

▶ Become job-ready with Python:

▶ Follow me on Instagram:
Рекомендации по теме
Комментарии
Автор

This is exactly what I needed thank you.

ranjit
Автор

Very interesting. Can't think of when I'd ever use it, but good to know

murphygreen
Автор

I like singledispatch. It's short and pythonic.

markmilan
Автор

Correction: The pipe syntax for unions is available as of python 3.10, see PEP-604

xoptics
Автор

Thumbnail 😢 there is just type annotation 😂 which will be ignored by python interpreter.... And mentioned it as fn overloading 😂😂😂😊 just fun, comments on thumbnail only not content😊

tech-learner
Автор

In curious if this also works with dunder methods.. recently I've wanted to have two separate class initiallizers, one that takes individual parameters and one that takes dictionary, as someone who's done fair bit of coding in c++ I got quite disappointed when I found out that python doesn't natively support overloading, which is really useful thing most of the time..

MyManJohnny
Автор

Hey Federico!
I'm a big fan of your tutorials.
Could you create a video covering 'multiple dispatch'?

MrBirjand
Автор

How does this compare to the isinstance checking approach speed-wise and memory-wise?

VojtechMach
Автор

I don't see the name of overloaded functions as _, what if I have more than 1 function overloaded?

Akn
Автор

Can the type be used simultaneously in the decorator and the function definition?

pschweitzer
Автор

I think the code could be just as readable if you gave each function its own name

davidznidarsic
Автор

I have an increasingly stronger feeling that people are trying to supercharge Python - a simple scripting language - with concepts which are not natively supported by the language by decorators, behind-the-scenes meta-magic or creating countless tools around it.
Examples - everloading using decorators, pytest with its hidden/implicit fixture and monkeypatch functionality or countless tools to run rigorous type checks/validations (pydantic, mypy, pyre, etc.) in a type-loose languge. It feels kinda like dressing a dog in brand clothes and pretending it is a teenager.

VojtechMach