mirror of
https://github.com/python/cpython.git
synced 2025-11-01 10:45:30 +00:00
bpo-43698: do not use ... as argument name in docs (GH-30502)
This commit is contained in:
parent
84f093918a
commit
b9d8980d89
4 changed files with 16 additions and 19 deletions
|
|
@ -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
|
you can create a dictionary mapping case values to functions to call. For
|
||||||
example::
|
example::
|
||||||
|
|
||||||
def function_1(...):
|
|
||||||
...
|
|
||||||
|
|
||||||
functions = {'a': function_1,
|
functions = {'a': function_1,
|
||||||
'b': function_2,
|
'b': function_2,
|
||||||
'c': self.method_1, ...}
|
'c': self.method_1}
|
||||||
|
|
||||||
func = functions[value]
|
func = functions[value]
|
||||||
func()
|
func()
|
||||||
|
|
@ -279,14 +276,14 @@ example::
|
||||||
For calling methods on objects, you can simplify yet further by using the
|
For calling methods on objects, you can simplify yet further by using the
|
||||||
:func:`getattr` built-in to retrieve methods with a particular name::
|
: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):
|
def dispatch(self, value):
|
||||||
method_name = 'visit_' + str(value)
|
method_name = 'visit_' + str(value)
|
||||||
method = getattr(self, method_name)
|
method = getattr(self, method_name)
|
||||||
method()
|
method()
|
||||||
|
|
||||||
It's suggested that you use a prefix for the method names, such as ``visit_`` in
|
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
|
this example. Without such a prefix, if values are coming from an untrusted
|
||||||
|
|
|
||||||
|
|
@ -282,12 +282,12 @@ Glossary
|
||||||
The decorator syntax is merely syntactic sugar, the following two
|
The decorator syntax is merely syntactic sugar, the following two
|
||||||
function definitions are semantically equivalent::
|
function definitions are semantically equivalent::
|
||||||
|
|
||||||
def f(...):
|
def f(arg):
|
||||||
...
|
...
|
||||||
f = staticmethod(f)
|
f = staticmethod(f)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def f(...):
|
def f(arg):
|
||||||
...
|
...
|
||||||
|
|
||||||
The same concept exists for classes, but is less commonly used there. See
|
The same concept exists for classes, but is less commonly used there. See
|
||||||
|
|
|
||||||
|
|
@ -186,15 +186,15 @@ The :mod:`abc` module also provides the following decorator:
|
||||||
|
|
||||||
class C(ABC):
|
class C(ABC):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def my_abstract_method(self, ...):
|
def my_abstract_method(self, arg1):
|
||||||
...
|
...
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def my_abstract_classmethod(cls, ...):
|
def my_abstract_classmethod(cls, arg2):
|
||||||
...
|
...
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def my_abstract_staticmethod(...):
|
def my_abstract_staticmethod(arg3):
|
||||||
...
|
...
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -255,7 +255,7 @@ The :mod:`abc` module also supports the following legacy decorators:
|
||||||
class C(ABC):
|
class C(ABC):
|
||||||
@classmethod
|
@classmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def my_abstract_classmethod(cls, ...):
|
def my_abstract_classmethod(cls, arg):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -276,7 +276,7 @@ The :mod:`abc` module also supports the following legacy decorators:
|
||||||
class C(ABC):
|
class C(ABC):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def my_abstract_staticmethod(...):
|
def my_abstract_staticmethod(arg):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ are always available. They are listed here in alphabetical order.
|
||||||
|
|
||||||
class C:
|
class C:
|
||||||
@classmethod
|
@classmethod
|
||||||
def f(cls, arg1, arg2, ...): ...
|
def f(cls, arg1, arg2): ...
|
||||||
|
|
||||||
The ``@classmethod`` form is a function :term:`decorator` -- see
|
The ``@classmethod`` form is a function :term:`decorator` -- see
|
||||||
:ref:`function` for details.
|
:ref:`function` for details.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue