-
Notifications
You must be signed in to change notification settings - Fork 98
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
Ensure that spec is deep copiable #360
Ensure that spec is deep copiable #360
Conversation
0ab2830
to
4caa156
Compare
return False | ||
|
||
if id(self) == id(other): | ||
return True |
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.
Wouldn't it make sense to put the id check first?
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.
👍
bravado_core/spec.py
Outdated
# all the attributes. | ||
# NOTE: Few attributes have recursive references to Spec or do not define an equality method we're going to blacklist them | ||
return all( | ||
getattr(self, attr_name, None) == getattr(other, attr_name, None) |
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.
This seems wrong to me - it allows the equality check to pass if one instance has the attribute set, while the other hasn't.
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'm going to update the return statement in the following way:
- going to use a for loop instead of using
all
as it can simplify reading - going to use
getattr(self, attr_name) != getattr(other, attr_name)
check - going to catch
AttributeError
exception to ensure that differences in the defined attributes cause equality check to return False
…he defined attributes are different
A
bravado_core.spec.Spec
instance is currently not deep copiable.So running something like
deepcopy(Spec.from_dict(<valid_specs>))
results on an unbounded recursion error.The goal of this PR is to address this issue by defining the
__deepcopy__
dunder method.