From 864b2b793178e011702e0c5440e2273b15041f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 12 Oct 2017 11:05:32 -0400 Subject: [PATCH 1/3] fix missed decorator markup --- Doc/library/typing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index bd04f731a1238b..1c13fe2476e9ff 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -897,7 +897,7 @@ The module defines the following classes, functions and decorators: See :pep:`484` for details and comparison with other typing semantics. -.. decorator:: no_type_check(arg) +.. decorator:: no_type_check Decorator to indicate that annotations are not type hints. @@ -907,7 +907,7 @@ The module defines the following classes, functions and decorators: This mutates the function(s) in place. -.. decorator:: no_type_check_decorator(decorator) +.. decorator:: no_type_check_decorator Decorator to give another decorator the :func:`no_type_check` effect. From d054b706b7e090f30ad8adf9efc2ca36c1be1a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 12 Oct 2017 11:20:25 -0400 Subject: [PATCH 2/3] clarify usage --- Doc/library/typing.rst | 2 +- Lib/test/test_typing.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 1c13fe2476e9ff..9883d8bbe86596 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -901,7 +901,7 @@ The module defines the following classes, functions and decorators: Decorator to indicate that annotations are not type hints. - The argument must be a class or function; if it is a class, it + This works as class or function :term:`decorator`. With a class, it applies recursively to all methods defined in that class (but not to methods defined in its superclasses or subclasses). diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py index 87d707c1cde6f3..a3b6eb933935e2 100644 --- a/Lib/test/test_typing.py +++ b/Lib/test/test_typing.py @@ -1471,8 +1471,8 @@ class D(C): def test_meta_no_type_check(self): @no_type_check_decorator - def magic_decorator(deco): - return deco + def magic_decorator(func): + return func self.assertEqual(magic_decorator.__name__, 'magic_decorator') From d781818d5f23acbde26c09d96ef1bb309d2310a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 12 Oct 2017 11:55:55 -0400 Subject: [PATCH 3/3] add example of regular function call usage --- Doc/library/functions.rst | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index eed67301c04973..e47225718c1b51 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -1419,12 +1419,21 @@ are always available. They are listed here in alphabetical order. :func:`classmethod` for a variant that is useful for creating alternate class constructors. + Like all decorators, it is also possible to call ``staticmethod`` as + a regular function and do something with its result. This is needed + in some cases where you need a reference to a function from a class + body and you want to avoid the automatic transformation to instance + method. For these cases, use this idiom: + + class C: + builtin_open = staticmethod(open) + For more information on static methods, consult the documentation on the standard type hierarchy in :ref:`types`. - .. index:: - single: string; str() (built-in function) +.. index:: + single: string; str() (built-in function) .. _func-str: .. class:: str(object='')