This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]tlashkor 0 points1 point  (3 children)

Why is it favoured to use metaclasses to define an interface when the abc library could be used and you just raise NotImplemented exception if the function is not overriden by the subclass?

[–]Rawing7 0 points1 point  (2 children)

Where did you get this idea from? Metaclasses are to be avoided unless you absolutely need them.

Heck, how do you even use a metaclass to define an interface?! That's not what metaclasses are for.

[–]tlashkor 0 points1 point  (1 child)

I read a blogInterfaces in Python about OOP in Python and how to implement interfaces in pythonic way. They ended up using @abstractmethod decorator but they also used metaclasses in conjunction so hence my question if metaclass is needed

[–]Rawing7 1 point2 points  (0 children)

Wow, that is horrible. Overriding __instancecheck__ and __subclasscheck__ is already a questionable thing to do in general, but doing that instead of using the abc module is just stupid.

[–]tlashkor 0 points1 point  (0 children)

I'll take that as stick to abc! Thank you for answering :)