0

I need to check if an argument is a type class. Not if an argument is of a specific type like int, but that is a type.

Here's some code illustrating what I want to achieve:

def is_type(arg):
    if arg is a type:
        return True
    return False


is_type(int) # true
is_type(str) # true
is_type(23) # false
is_type(type(23)) # true

What should the body of is_type be to achieve this? I tried if arg is type: but that's didn't work.

Ian Newson
  • 7,679
  • 2
  • 47
  • 80
  • 2
    I don't know who has closed your question with inappropriate duplicate. But the answer is also found here on SO. This is a duplicate of https://stackoverflow.com/questions/395735/how-to-check-whether-a-variable-is-a-class-or-not – sudden_appearance Feb 05 '22 at 22:52
  • 1
    @sudden_appearance Yeah, clearly they didn't read my question. However you did and linked a correct answer, so thanks! – Ian Newson Feb 05 '22 at 22:56

0 Answers0