What is the type of the compiled regular expression in python?
In particular, I want to evaluate
isinstance(re.compile(\'\'), ???)
As an illustration of polymorphism, an alternate solution is to create wrapper classes which implement a common method.
class Stringish (str):
def matches (self, input):
return self == input
class Regexish (re):
def matches (self, input):
return self.match(input)
Now your code can iterate over a list of alloweds containing objects instantiating either of these two classes completely transparently:
for allowed in alloweds:
if allowed.matches(input):
ignored = False
break
Notice also how some code duplication goes away (though your original code could have been refactored to fix that separately).