-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add decorators for gemmi argument checking #94
Conversation
To do:
|
Codecov Report
@@ Coverage Diff @@
## main #94 +/- ##
==========================================
+ Coverage 98.87% 98.97% +0.09%
==========================================
Files 40 41 +1
Lines 1512 1561 +49
==========================================
+ Hits 1495 1545 +50
+ Misses 17 16 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
if isinstance(sg, SpaceGroup): | ||
group_ops = sg.operations() | ||
elif isinstance(sg, GroupOps): | ||
group_ops = sg | ||
else: | ||
raise ValueError( | ||
f"gemmi.SpaceGroup or gemmi.GroupOps expected for parameter sg. " | ||
f"Received object of type: ({type(sg)}) instead." | ||
) | ||
|
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.
Note: This change removes support for invoking this function directly with a GroupOps
object. We do not actually use this anywhere in our codebase, so it seems like the added flexibility of @spacegroupify
is preferable. This is also true for is_absent()
and is_centric()
.
Fixes #92.
It is common in
rs
to write functions that takegemmi.SpaceGroup
orgemmi.UnitCell
instances as arguments. In order to make these methods more flexible, it is often useful to add error checking code so that if anint
is provided instead of agemmi.SpaceGroup
, the method generates the equivalentgemmi
object instance. This was done for theDataSet.cell
andDataSet.spacegroup
setter methods to address #18.This PR generalizes this idea using
@spacegroupify
and@cellify
decorators to avoid needing to write boiler plate argument checking code. This allows one to write a function as if it is guaranteed that the input argument is agemmi
object, while still being able to input that argument flexibly. For example: