Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

python: Fix __dict__ mutation abuse.

Anders Kaseorg5e1ebf2861c8
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index 674455f8e7d..e7ca327a5c5 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -173,12 +173,11 @@ def generate_and_save_stripe_fixture(
stripe_object = mocked_function(*args, **kwargs)
except stripe.error.StripeError as e:
with open(fixture_path, "w") as f:
- error_dict = e.__dict__
- error_dict["headers"] = dict(error_dict["headers"])
+ error_dict = {**vars(e), "headers": dict(e.headers)}
f.write(
json.dumps(error_dict, indent=2, separators=(",", ": "), sort_keys=True) + "\n"
)
- raise e
+ raise
with open(fixture_path, "w") as f:
if stripe_object is not None:
f.write(str(stripe_object) + "\n")
diff --git a/zerver/management/commands/list_realms.py b/zerver/management/commands/list_realms.py
index 0d7242ed0a0..aacb4f38d16 100644
--- a/zerver/management/commands/list_realms.py
+++ b/zerver/management/commands/list_realms.py
@@ -50,7 +50,7 @@ Usage examples:
for realm in realms:
# Start with just all the fields on the object, which is
# hacky but doesn't require any work to maintain.
- realm_dict = realm.__dict__
+ realm_dict = vars(realm).copy()
# Remove a field that is confusingly useless
del realm_dict["_state"]
# Fix the one bitfield to display useful data