
The proposal as it stands now only works for methods (and closely related concepts like properties), but a common pattern I have seen is to use class variables to configure behavior in child classes. For example, this pattern shows up in the standard library's webbrowser module (simplified from https://github.com/python/cpython/blob/f177f6f29b069f522a0b3ba44eaae19852b6d... ): class UnixBrowser(BaseBrowser): remote_args = ['%action', '%s'] def open(self, url): args = [arg.replace("%s", url) for arg in self.remote_args] self._invoke(args) class Netscape(UnixBrowser): remote_args = ['-remote', 'openURL(%s%action)'] This could give rise to the same kind of issues that your draft mentions for methods: if you rename the base class attribute, you may get hard-to-find bugs. However, you can't decorate an attribute. A solution could be to add a typing.Override special form, similar to Final: class Netscape(UnixBrowser): remote_args: Override = ['-remote', 'openURL(%s%action)'] # also allowed: remote_args: Override[list[str]] = ['-remote', 'openURL(%s%action)'] El mié, 17 ago 2022 a las 10:23, Steven Troxler (<steven.troxler@gmail.com>) escribió:
Thanks to everyone who provided feedback about an override decorator in last week’s meetup!
We have finished an initial draft proposal [1]. We’re happy to take comments and suggestions on this doc; we also looking for a sponsor so we can put a PR together.
We also specifically wanted to call out some edge cases that might be worth addressing in the “Specification” section related to how override interacts with regular attributes. The main override-specific question is whether we care about a way to mark attribute assignments as overrides, since they are subject to the same renaming bugs.
But that brings up a few more edge cases such as properties and methods that override attributes. We’ve drawn up a doc [2] highlighting all these edge cases and would love to hear feedback.
- Joshua Xu and Steven Troxler
------------------
[1] Draft PEP for @typing.override
https://docs.google.com/document/d/1dBkHKaOCqttnqzPo7kw1dzvbuFzNoOdx7OPyfbJH...
[2] Edge cases related to attributes
https://docs.google.com/document/d/1dhlcKKuYtGN9Eftr1hu9U6EKzsS0NPuQm01b7brj...
[3] Slides from last week's presentation https://drive.google.com/drive/folders/1sGZ0WBLaVBkCb0AT7tneCEwbATxgisI2
[4] Original thread regarding override
https://mail.python.org/archives/list/typing-sig@python.org/thread/V23I4D6DE... _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: jelle.zijlstra@gmail.com