Created
April 13, 2019 15:46
-
-
Save isidentical/1021c34363d1468bde8b4dd0d6e7a6cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ParentMeta(type): | |
def __new__(cls, name, bases, cls_dict): | |
cls = super().__new__(cls, name, bases, cls_dict) | |
cls.items = cls.items.copy() | |
return cls | |
class Parent(metaclass=ParentMeta): | |
items = [] | |
class Child(Parent): | |
pass | |
Parent.items.append(1) | |
Child.items.append(2) | |
assert Parent.items == [1] | |
assert Child.items == [2] | |
assert Child.items is not Parent.items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment