From 5e1ebf2861c8e2691e826915be802a288587076d Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 7 Oct 2022 22:04:09 -0700 Subject: [PATCH] python: Fix __dict__ mutation abuse. Signed-off-by: Anders Kaseorg --- corporate/tests/test_stripe.py | 5 ++--- zerver/management/commands/list_realms.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py index 674455f8e7..e7ca327a5c 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 0d7242ed0a..aacb4f38d1 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