[Python-Dev] Proposal: go back to enabling DeprecationWarning by default (original) (raw)
Random832 random832 at fastmail.com
Fri Nov 10 11:02:43 EST 2017
- Previous message (by thread): [Python-Dev] Proposal: go back to enabling DeprecationWarning by default
- Next message (by thread): [Python-Dev] Proposal: go back to enabling DeprecationWarning by default
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Nov 7, 2017, at 07:22, Nick Coghlan wrote:
My suggestion for that definition is to have the default meaning of "third party code" be "everything that isn't main".
What is main? Or, rather, how do you determine when it is to blame? For syntax it's easy, but any deprecated function necessarily belongs to its own module and not to main. Main may have called it, which can be detected from the stack trace, or it may have used it in some other way (pass to some builtin or e.g. itertools function that takes a callable argument, for example). Maybe the DeprecationWarning should be raised at the name lookup* rather than the call? What if "calling this function with some particular combination of arguments" is deprecated?
*i.e. something like:
class deprecated: def init(self, obj): self.obj = obj class DeprecatableModule(ModuleType): def getattr(self, name): obj = self.dict[name] if isinstance(type(obj), deprecated): if (detect somehow caller is main): raise DeprecationWarning return obj.obj else: return obj def dir(self): return [k for k in self.dict if not isinstance(self.dict[k], deprecated)]
sys.modules[name].type=DeprecatableModule
@deprecated def some_deprecated_function(...): ...
SOME_DEPRECATED_CONSTANT = deprecated(42)
- Previous message (by thread): [Python-Dev] Proposal: go back to enabling DeprecationWarning by default
- Next message (by thread): [Python-Dev] Proposal: go back to enabling DeprecationWarning by default
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]