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.
pull/1/head
Michael Chisholm 2021-01-20 19:42:06 -05:00
parent 5aadf1ae91
commit 92a478b39b
1 changed files with 7 additions and 3 deletions

View File

@ -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()