Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
metaclass
#1
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
Reply
#2
I think you forgot something.
Reply
#3
(Aug-26-2021, 05:26 PM)deanhystad Wrote: I think you forgot something.

yes sorry
class ForceToList(Ex,metaclass=MetaInherList()):
    pass
Reply
#4
re!
personne?
Reply
#5
I'm sure your teacher didn't formulate the question this way, because as it is, it is incomprehensible.
Reply
#6
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?
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020