-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repost with deletions/edits v1 #3687
Changes from all commits
249191d
76058da
3d9b327
bb3dc8e
e07e627
f3361d6
5fb7703
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
build: | ||
rm types/v2/* -rf | ||
rm -rf types/v2/* | ||
touch types/v2/__init__.py | ||
cd types/v2/ && protoc --python_out=. -I ../../../../../types/v2/proto/ ../../../../../types/v2/proto/*.proto | ||
cd types/v2/ && cp ../../../../../types/jsonschema/* ./ | ||
sed -e 's/^import\ \(.*\)_pb2\ /from . import\ \1_pb2\ /g' -i types/v2/*.py | ||
sed -e 's/^import\ \(.*\)_pb2\ /from . import\ \1_pb2\ /g' -i.bak types/v2/*.py |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,7 @@ def none_check(self, kwargs): | |
if value is None: | ||
raise InputValueIsNoneError(key) | ||
|
||
def update(self, **kwargs): | ||
def update(self, strict_update=True, **kwargs) -> dict: | ||
self.none_check(kwargs) | ||
|
||
for key in list(kwargs): | ||
|
@@ -136,8 +136,22 @@ def update(self, **kwargs): | |
|
||
for l in self.repeat_fields: | ||
field = getattr(self, l) | ||
if kwargs.pop(f'clear_{l}', False): | ||
del field[:] | ||
clear = kwargs.pop(f'clear_{l}', False) | ||
if isinstance(clear, bool) and clear: | ||
failed = [] | ||
if len(field) > 0: | ||
del field[:] | ||
else: | ||
failed = clear | ||
if failed: | ||
kwargs[f'clear_{l}'] = failed | ||
if isinstance(clear, list): | ||
failed = [] | ||
for c in clear: | ||
if not field.remove(c): | ||
failed.append(c) | ||
if failed: | ||
kwargs[f'clear_{l}'] = failed | ||
items = kwargs.pop(l, None) | ||
if items is not None: | ||
if isinstance(items, str): | ||
|
@@ -147,8 +161,16 @@ def update(self, **kwargs): | |
else: | ||
raise ValueError(f"Unknown {l} value: {items}") | ||
|
||
failed = dict() | ||
for key, value in kwargs.items(): | ||
setattr(self, key, value) | ||
try: | ||
setattr(self, key, value) | ||
except AttributeError: | ||
failed[key] = value | ||
if strict_update: | ||
raise | ||
|
||
return failed | ||
|
||
@property | ||
def title(self) -> str: | ||
|
@@ -213,7 +235,7 @@ def to_dict(self): | |
fee['amount'] = str(self.fee.amount) | ||
return claim | ||
|
||
def update(self, file_path=None, height=None, width=None, duration=None, **kwargs): | ||
def update(self, file_path=None, height=None, width=None, duration=None, **kwargs) -> dict: | ||
|
||
if kwargs.pop('clear_fee', False): | ||
self.message.ClearField('fee') | ||
|
@@ -264,7 +286,7 @@ def update(self, file_path=None, height=None, width=None, duration=None, **kwarg | |
media_args['width'] = width | ||
media.update(**media_args) | ||
|
||
super().update(**kwargs) | ||
return super().update(**kwargs) | ||
|
||
@property | ||
def author(self) -> str: | ||
|
@@ -398,6 +420,18 @@ class Repost(BaseClaim): | |
|
||
claim_type = Claim.REPOST | ||
|
||
def update(self, **kwargs) -> dict: | ||
claim_type = kwargs.pop('claim_type', None) | ||
# Update common fields within BaseClaim. | ||
kwargs = super().update(strict_update=False, **kwargs) | ||
if claim_type: | ||
# Remaining updates go into deletes/edits of ClaimReference. | ||
kwargs = self.reference.update(claim_type, **kwargs) | ||
return kwargs | ||
Comment on lines
+423
to
+430
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See PR description. This is where I have a choice of applying the update to BaseClaim or stuff it inside ClaimReference. |
||
|
||
def apply(self, reposted: 'Claim'): | ||
return self.reference.apply(reposted) | ||
|
||
@property | ||
def reference(self) -> ClaimReference: | ||
return ClaimReference(self.message) | ||
|
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to have to use this to get "make elastic-docker" to work. Is it just me? (MacOS aarch64)