diff options
author | Nikita Sobolev <mail@sobolevn.me> | 2022-01-26 10:06:10 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-26 10:06:10 (GMT) |
commit | b9d8980d89bfaa4bf16d60f0488adcc9d2cbf5ef (patch) | |
tree | 9aedd5f139c75c9f5d653bdb734a93de7a68235d /Doc/faq | |
parent | 84f093918a4be663775afe2933f4be86f72fe495 (diff) | |
download | cpython-b9d8980d89bfaa4bf16d60f0488adcc9d2cbf5ef.zip cpython-b9d8980d89bfaa4bf16d60f0488adcc9d2cbf5ef.tar.gz cpython-b9d8980d89bfaa4bf16d60f0488adcc9d2cbf5ef.tar.bz2 |
bpo-43698: do not use `...` as argument name in docs (GH-30502)
Diffstat (limited to 'Doc/faq')
-rw-r--r-- | Doc/faq/design.rst | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 0437b59..ff83a1b 100644 --- a/Doc/faq/design.rst +++ b/Doc/faq/design.rst @@ -266,12 +266,9 @@ For cases where you need to choose from a very large number of possibilities, you can create a dictionary mapping case values to functions to call. For example:: - def function_1(...): - ... - functions = {'a': function_1, 'b': function_2, - 'c': self.method_1, ...} + 'c': self.method_1} func = functions[value] func() @@ -279,14 +276,14 @@ example:: For calling methods on objects, you can simplify yet further by using the :func:`getattr` built-in to retrieve methods with a particular name:: - def visit_a(self, ...): - ... - ... + class MyVisitor: + def visit_a(self): + ... - def dispatch(self, value): - method_name = 'visit_' + str(value) - method = getattr(self, method_name) - method() + def dispatch(self, value): + method_name = 'visit_' + str(value) + method = getattr(self, method_name) + method() It's suggested that you use a prefix for the method names, such as ``visit_`` in this example. Without such a prefix, if values are coming from an untrusted |