aiidateam / aiida-core

The official repository for the AiiDA code
https://aiida-core.readthedocs.io
Other
431 stars 187 forks source link

ORM: Fix deprecation warning being shown for new code types #6407

Closed sphuber closed 4 months ago

sphuber commented 4 months ago

The InstalledCode and PortableCode have been introduced already some time ago as the refactored version of the legacy Code class. The latter has been deprecated for that reason, but for backwards compatibility reasons, the new implementations still need to keep the legacy class as a base class. Unfortunately, this meant that the deprecation warning was also shown when users instantiated an instance of the new classes, which would be confusing.

The deprecation warning had already been moved from module level to the constructor of the Code class to prevent it from showing merely upon import of the aiida.orm package. As a final work around, the new classes define the _EMIT_CODE_DEPRECATION_WARNING class attribute which is checked in the Code constructor such that when set, the deprecation warning is skipped.

sphuber commented 4 months ago

This seems to do the trick. Credits to @giovannipizzi I remember him mentioning an approach like this somewhere sometime ago.