From 92a478b39b25f6cd6c9cbd14c597aa75325be1bb Mon Sep 17 00:00:00 2001 From: Michael Chisholm Date: Wed, 20 Jan 2021 19:42:06 -0500 Subject: [PATCH] A minor revision to stix2.versioning: it's silly to look up a class in the registry when you have an instance of one of those classes. Because in that case, you can just get the class of the instance and not deal with the registry at all. --- stix2/versioning.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/stix2/versioning.py b/stix2/versioning.py index 7e1336a..336ea4a 100644 --- a/stix2/versioning.py +++ b/stix2/versioning.py @@ -168,11 +168,15 @@ def new_version(data, allow_custom=None, **kwargs): # across versions. sco_locked_props = [] if is_sco(data, "2.1"): - cls = stix2.registry.class_for_type( - data["type"], stix_version, "observables" - ) uuid_ = uuid.UUID(data["id"][-36:]) if uuid_.variant == uuid.RFC_4122 and uuid_.version == 5: + if isinstance(data, stix2.base._Observable): + cls = data.__class__ + else: + cls = stix2.registry.class_for_type( + data["type"], stix_version, "observables" + ) + sco_locked_props = cls._id_contributing_properties unchangable_properties = set()