1
import abc
class SetterGetter(object):
 __metaclass__ = abc.ABCMeta
 @abc.abstractmethod
 def set_val(self, inp):
 return
 @abc.abstractmethod
 def get_val(self):
 return
class TryAbsMethod(SetterGetter):
 def get_val(self):
 return self.inp
 def set_valz(self, inp):
 self.inp = inp
a = TryAbsMethod()
print(a)

As per tutorial, I was expecting excption from above code but instead I got output from python which is strange, Can someone please explain me why?

Output got

/usr/bin/python3.4 /home/murtuza/MyCodes/abstract.py
<__main__.TryAbsMethod object at 0x7f93ba8ab048>
Process finished with exit code 0

Exception Which is expected

TypeError: Can't instantiate abstract class TryAbsMethod with abstract method set_val
asked Sep 7, 2015 at 4:49
2

1 Answer 1

1

You're using Python 3.x. In Python 3.x, metaclass declaring syntax is changed.

class SetterGetter(object, metaclass=abc.ABCMeta): # <---
 @abc.abstractmethod
 def set_val(self, inp):
 return
 @abc.abstractmethod
 def get_val(self):
 return

See Customizing class creation - Data model - Python 3.x documentation, PEP3115 - Metaclasses in Python 3

answered Sep 7, 2015 at 4:54
Sign up to request clarification or add additional context in comments.

2 Comments

@RajeshChoudhary, Please post a question, instead of commenting on irrelevant answers.
this is my question please see this stackoverflow.com/questions/32519620/…

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.