A class attribute provides a default that’s the same for all instances, but does let you customize it with a simple attribute assignment. Which seems like the right thing in this case.
class Cmd: > PROMPT = '> ' > > @property > def prompt(self) -> str: > return self.PROMPT This makes .prompt a read-only instance attribute. So you then wouldn’t be able to change it for a given instance. Why make it an instance attribute if all instances will have the same one? Unless you want to disallow overriding it in an instance. If the reason is to make MyPy happy, then either there’s a big in your code, or MyPy is being overly pedantic. NOTE: accessing class attributes via self is standard practice — after all methods are simply callable class attributes :-) -CHB > _______________________________________________ > Python-Dev mailing list -- python-dev@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/Q7TSFJD4EPUXXJFT5TMBUODIVL4CLR4O/ > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/GAU3BJFQ2OYLQSRPIWZKH7CKFCK76L32/ Code of Conduct: http://python.org/psf/codeofconduct/