Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do you mark an entire file as deprecated in Python?

I am reviewing a .py file with no classes, just a list of functions. There is a newer version of this same file which is now used instead of the old file.

I know to mark class or function as deprecated, one can do from warnings import deprecated and then for the decorated function or class use deprecated("Do not use this")

There is not a 1-1 correspondence, so marking all the functions as deprecated individually seems weird. I could wrap the code in a class, deprecate this newly created class, and be done with it. However, it would be more natural to have a single annotation at the top of the page saying the entire contents of the file are to be ignored.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I could also create a new package, say deprecated, and move it there, but I would rather it keep the code in its original location.

So is there a pythonic way to mark an entire file as deprecated?

>Solution :

You could raise a DeprecationWarning at the top of the file. So it is issued whenever it is imported.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading