I have a class with a string property defined on it.
class Foo(object):
@property
def kind(self):
return 'bar'
There's some third party code that I want to pass this property to that asserts that the property is a str
:
third party:
def baz(kind):
if not isinstance(kind, (str, unicode)):
message = ('%.1024r has type %s, but expected one of: %s' %
(kind, type(kind), (str, unicode)))
raise TypeError(message)
me:
foo = Foo()
baz(foo.kind)
output:
TypeError: <property object at 0x11013e940> has type <type 'property'>, but expected one of: (<type 'str'>, <type 'unicode'>)
Is there any way I can make the python object have a property with str
type rather than property
type?
EDIT:
Original question is wrong, I was actually calling
Foo.kind
as pointed out by Martijn Pieters below.