-
Notifications
You must be signed in to change notification settings - Fork 127
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
Undocumented usage of reserved dunder names #630
Comments
Honestly I think this is a perfectly acceptable use of a dunder method. The python docs are warning that from their perspective the |
The choice to use dunder method names affects not only this particular protocol, but any future ones we decide to add to this library, and other Qiskit libraries if we want to be consistent across Qiskit. So while these specific names may be unlikely to break, relying on future name choices to also be unlikely to be broken is somewhat tenuous. The choice of protocol name affects not only this library, but any user code or other libraries that implement this protocol. If the protocol is broken, their code would also be broken, even if we update the names here. |
This isn't really a bug, it's a suggest change to an existing internal API. Since this is an API that is currently in use I don't see this as sufficient justification for introducing breaking changes to it. If it actually becomes a problem in future we can revisit then, but as @mtreinish said this seems quite unlikely, so for now I'm closing this issue. |
Informations
What is the current behavior?
The JSON serialization framework (https://github.com/Qiskit/qiskit-experiments/blob/a0beb41ec0757429031e0e6e7a7855dcc72877cd/qiskit_experiments/framework/json.py) relies on classes defining their own methods called
__json_encode__
and__json_decode__
. These names are bad choices because they are explicitly documented as subject to breakage in future Python versions. From https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers:Steps to reproduce the problem
N/A
What is the expected behavior?
Reserved dunder method names should not be used in undocumented ways.
Suggested solutions
The method names
__json_encode__
and__json_decode__
and any other such names in the library should be changed. I suggest using a single underscore instead of a double, i.e._json_encode_
.The text was updated successfully, but these errors were encountered: