On Mon, Apr 26, 2021 at 4:58 AM Shreyan Avigyan
<pythonshreya...@gmail.com> wrote:
>
> First of all the use case is when for example we have UserDefined class and 
> my function or another class can only handle instances of the UserDefined 
> class. Second of all why not add a built-in type check decorator then?
>

What if it's a subclass of that class, though? If you check if the
type is equal to something, you'd unnecessarily reject subclasses.

And, because MOST programs don't need that sort of checking. It's
completely unnecessary. Just write your code without checks, and let
people call your function with any object that is suitable - that's
the essence of duck typing, and it's far easier to work with. Don't
write the checking code, and that way, it can't be buggy; as a bonus,
your function is more flexible.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/77SRHMQQEQ6G4DEPG2W443KUJGDVSZUH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to