kopia lustrzana https://gitlab.com/jaywink/federation
Move mutable entity attribute defaults to __init__
Got bitten by defining mutable type defaults as class attributes. Moved them to class __init__ to ensure attributes are not shared across instances.merge-requests/130/head
rodzic
78d344d6a8
commit
bbd85571a1
|
@ -10,8 +10,6 @@ __all__ = (
|
|||
|
||||
|
||||
class BaseEntity(object):
|
||||
_required = []
|
||||
_children = []
|
||||
_allowed_children = ()
|
||||
# If we have a receiver for a private payload, store receiving user guid here
|
||||
_receiving_guid = ""
|
||||
|
@ -22,6 +20,7 @@ class BaseEntity(object):
|
|||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._required = []
|
||||
self._children = []
|
||||
for key, value in kwargs.items():
|
||||
if hasattr(self, key):
|
||||
setattr(self, key, value)
|
||||
|
@ -287,17 +286,20 @@ class Profile(CreatedAtMixin, HandleMixin, OptionalRawContentMixin, PublicMixin,
|
|||
"""Represents a profile for a user."""
|
||||
name = ""
|
||||
email = ""
|
||||
image_urls = {
|
||||
"small": "", "medium": "", "large": ""
|
||||
}
|
||||
gender = ""
|
||||
location = ""
|
||||
nsfw = False
|
||||
tag_list = []
|
||||
public_key = ""
|
||||
|
||||
_allowed_children = (Image,)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.image_urls = {
|
||||
"small": "", "medium": "", "large": ""
|
||||
}
|
||||
self.tag_list = []
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def validate_email(self):
|
||||
if self.email:
|
||||
validator = Email()
|
||||
|
|
Ładowanie…
Reference in New Issue