They Said THIS Was Impossible In Python

preview_player
Показать описание
They said this was impossible in Python #python #code #shorts
Рекомендации по теме
Комментарии
Автор

This is the definition of just because you can doesn't mean you should

seventeeen
Автор

You could also use checking the types with `if type(arg) …` checks and make it do different things based on the type, but this seems like a cleaner solution that mimics strongly typed languages.

coolcodingcat
Автор

I know about partial functions in Python but function overloading is so cool.

CountryCalledCHAD
Автор

Looks painful, I would rather make peace with “python doesn’t support function overloading”

ravikatiyar
Автор

I think this simulates real function overloading using reflection. Decorators are really powerful tools that can hide a thon of stuff behind some concise yet vague syntax.

stefanoctaviansterea
Автор

we can overload functions with three methods (with if /match case )
2.In this method we can achieve the function overloading by user-defined function using the “None”
Keyword as the default parameter.
3. using multipledispatch
from multipledispatch import dispatch

and ofcource your way( the three )

xzex
Автор

Ever heard of the factory design pattern?

pradyumnachakraborty
Автор

There is a Multiple Dispatch, too, but that has to be installed with pip, conda, etc

apmcd
Автор

why don't you ( for this example) use (if/match case) of is_instance(object, arg) and with less lines of code define what the function do, due to the input type ??

xzex
Автор

I already know where I'm going to use this. I've been using isinstance, but this looks so much cleaner. I can finally tackle that big function and break it down to nice small chunks.

rnseby
Автор

Ooo, rozprawka bardzo dla mnie, , ,amerykanisty'' (nawet nie znałem tego słowa!). Dziękuję!

bartlomiejkubica
Автор

I'd rather use if/elif/else than this

cycrothelargeplanet
Автор

def func(arg):
if type(arg) == str:
do somthing
if type(arg) in [float, int]:
do something else

callbettersaul
Автор

I thought you needed to use typing's overload decorator 😅

developer_anonymous
Автор

I thought this was a unique feature of Object Oriented Programming

adventuresofavalon
Автор

Honestly seems way too cumbersome. Especially since you can use named arguments with default values.

AWriterWandering
Автор

I can't think of any practical use of this.

kpbendeguz
Автор

if type(arg) is str:
doThis
if type(arg) is int:
doThat

Saheryk
Автор

isn't is easier to use **kwargs and testing the name and type of a parameter?

HarmSalomons
Автор

Wait whoah I had no idea this applied to functions and not just methods

magicalbologna