deprecation
deprecation copied to clipboard
Support deprecation of (module level) variables
Hi. I just hit and interesting use case that I was not able to solve with this library. There is a module level variable and it's name has changed. Since is is not a function, I cannot decorate it with @deprecated(...)
.
I searched for possible solutions and found a couple of them in here: https://stackoverflow.com/questions/922550/how-to-mark-a-global-as-deprecated-in-python I liked the second solution with the Deprecated class, becasue it is similar to @deprecated(...)
and would allow to have the same interface.
I'm considering making a pull request but would like to check first if there would be an appetite for that.
I've been thinking about something like this as well as for actual modules themselves, so yeah, I'd like to see what's possible here—go ahead with a PR and I'll do whatever I can to help out. I wonder if it's possible to have one piece of code do what is currently being done as a decorator while also supporting your use-case, though? As in, perhaps the existing deprecated
function switches to being implemented as a class to cover both, rather than possibly having two ways to do it (though I'm not sure if that's what you were suggesting).
That answer by Unknown
looks like a pretty good starting point for something like this.
That would be ideal if there would be one thing that could do both. But the use cases are incompatible:
- Decorator has to return a function that accepts the decorated function.
- Variable deprecation has to return something compatible with the original type (for example if the deprecated thing is a variable with string, the return value has to look like string). Anyway, I opened a PR: https://github.com/briancurtin/deprecation/pull/35
It is currently failing on Python2. I'll check why and if it can be fixed.
It is fixed now :)