metaclass - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: metaclass (/thread-34737.html) |
metaclass - Bric - Aug-26-2021 hello I am doing an exercise and I am stuck on a part that I do not understand too much (metaclass). I need to write the MetaInherList metaclass for the ForceToList class to inherit from the built-in list. (read test_meta_list in tests for more information) def test_meta_list(): test = ForceToList([1, 2]) assert test[1] == 2 assert test.x == 4 class MetaInherList: # todo exercise pass RE: metaclass - deanhystad - Aug-26-2021 I think you forgot something. RE: metaclass - Bric - Aug-26-2021 (Aug-26-2021, 05:26 PM)deanhystad Wrote: I think you forgot something. yes sorry class ForceToList(Ex,metaclass=MetaInherList()): pass RE: metaclass - Bric - Aug-28-2021 re! personne? RE: metaclass - Gribouillis - Aug-28-2021 I'm sure your teacher didn't formulate the question this way, because as it is, it is incomprehensible. RE: metaclass - ndc85430 - Aug-29-2021 The test looks self-explanatory to me. Is it actually correct though? There's no assertion that checks that the instance of ForceToList is actually a list, so one can get it to pass without doing any inheritance at all.In any case, if you're being asked to do this, surely you must have learnt something about metaclasses in your class and/or been directed to reading on the subject? Going through those learning materials, what have you tried to solve the problem? |