
On Mon, Apr 26, 2021 at 4:58 AM Shreyan Avigyan <pythonshreyan09@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