Skip to content

Instantly share code, notes, and snippets.

@isidentical
Created April 13, 2019 15:46
Show Gist options
  • Save isidentical/1021c34363d1468bde8b4dd0d6e7a6cb to your computer and use it in GitHub Desktop.
Save isidentical/1021c34363d1468bde8b4dd0d6e7a6cb to your computer and use it in GitHub Desktop.
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