From ff12c5e57f2ce2fb5386af96734889a827d8afe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87EL=C4=B0K?= Date: Tue, 31 Mar 2020 22:34:34 +0300 Subject: [PATCH 01/18] bpo-29418 add new function called ismethodwrapper and fix this issue --- Lib/inspect.py | 7 ++++++- Lib/test/test_inspect.py | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index eb45f81aa2d959..7aba608f631bba 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -509,12 +509,17 @@ def isbuiltin(object): __self__ instance to which a method is bound, or None""" return isinstance(object, types.BuiltinFunctionType) +def ismethodwrapper(object): + "return True if the object is a method-wrapper" + return isinstance(object, types.MethodWrapperType) + def isroutine(object): """Return true if the object is any kind of function or method.""" return (isbuiltin(object) or isfunction(object) or ismethod(object) - or ismethoddescriptor(object)) + or ismethoddescriptor(object) + or ismethodwrapper(object)) def isabstract(object): """Return true if the object is an abstract base class (ABC).""" diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 29589a726768f5..98238dda00349e 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -243,6 +243,11 @@ class NotFuture: pass def test_isroutine(self): self.assertTrue(inspect.isroutine(mod.spam)) self.assertTrue(inspect.isroutine([].count)) + # to method-wrapper + self.assertTrue(inspect.isroutine(object().__init__)) + self.assertTrue(inspect.isroutine(object().__str__)) + self.assertTrue(inspect.isroutine(object().__lt__)) + self.assertTrue(inspect.isroutine((42).__lt__)) def test_isclass(self): self.istest(inspect.isclass, 'mod.StupidGit') From 22f15beb0306a9a5c4ff0aad6980c9a22af5c542 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87EL=C4=B0K?= Date: Tue, 31 Mar 2020 23:13:32 +0300 Subject: [PATCH 02/18] Usage some types from types module to prevent redefinition --- Lib/inspect.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 7aba608f631bba..904067ba13904a 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -1892,13 +1892,9 @@ def getcoroutinelocals(coroutine): ############################################################################### -_WrapperDescriptor = type(type.__call__) -_MethodWrapper = type(all.__call__) -_ClassMethodWrapper = type(int.__dict__['from_bytes']) - -_NonUserDefinedCallables = (_WrapperDescriptor, - _MethodWrapper, - _ClassMethodWrapper, +_NonUserDefinedCallables = (types.WrapperDescriptorType, + types.MethodWrapperType, + types.ClassMethodDescriptorType, types.BuiltinFunctionType) @@ -2538,7 +2534,7 @@ def _signature_from_callable(obj, *, elif not isinstance(obj, _NonUserDefinedCallables): # An object with __call__ # We also check that the 'obj' is not an instance of - # _WrapperDescriptor or _MethodWrapper to avoid + # types.WrapperDescriptorType or types.MethodWrapperType to avoid # infinite recursion (and even potential segfault) call = _signature_get_user_defined_method(type(obj), '__call__') if call is not None: From cc36777280930718007638cf18942d3d101411d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87EL=C4=B0K?= Date: Tue, 31 Mar 2020 23:14:11 +0300 Subject: [PATCH 03/18] Write doc to ismethodwrapper function --- Doc/library/inspect.rst | 5 +++++ Lib/inspect.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 711f510d7dcb03..e8b0674486eb27 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -429,6 +429,11 @@ attributes: Return ``True`` if the object is a built-in function or a bound built-in method. +.. function:: ismethodwrapper(object) + + Return ``True`` if the object is a method-wrapper. + + .. function:: isroutine(object) Return ``True`` if the object is a user-defined or built-in function or method. diff --git a/Lib/inspect.py b/Lib/inspect.py index 904067ba13904a..1d3e41a870e006 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -510,7 +510,7 @@ def isbuiltin(object): return isinstance(object, types.BuiltinFunctionType) def ismethodwrapper(object): - "return True if the object is a method-wrapper" + """return True if the object is a method-wrapper.""" return isinstance(object, types.MethodWrapperType) def isroutine(object): From 1642387c1623af1dda6f60669cb1a00adb422f3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87EL=C4=B0K?= Date: Tue, 31 Mar 2020 23:27:12 +0300 Subject: [PATCH 04/18] More test write to isroutine function of inspect module --- Lib/test/test_inspect.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 98238dda00349e..911e6c7012c09e 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -241,13 +241,35 @@ class NotFuture: pass coro.close(); gen_coro.close() # silence warnings def test_isroutine(self): - self.assertTrue(inspect.isroutine(mod.spam)) + # to method + self.assertTrue(inspect.isroutine(git.argue)) + self.assertTrue(inspect.isroutine(mod.custom_method)) self.assertTrue(inspect.isroutine([].count)) + # to function + self.assertTrue(inspect.isroutine(mod.spam)) + self.assertTrue(inspect.isroutine(mod.StupidGit.abuse)) + # to slot-wrapper + self.assertTrue(inspect.isroutine(object.__init__)) + self.assertTrue(inspect.isroutine(object.__str__)) + self.assertTrue(inspect.isroutine(object.__lt__)) + self.assertTrue(inspect.isroutine(int.__lt__)) # to method-wrapper self.assertTrue(inspect.isroutine(object().__init__)) self.assertTrue(inspect.isroutine(object().__str__)) self.assertTrue(inspect.isroutine(object().__lt__)) self.assertTrue(inspect.isroutine((42).__lt__)) + # to method-descriptor + self.assertTrue(inspect.isroutine(str.join)) + self.assertTrue(inspect.isroutine(list.append)) + self.assertTrue(inspect.isroutine(''.join)) + self.assertTrue(inspect.isroutine([].append)) + # to object + self.assertFalse(inspect.isroutine(object)) + self.assertFalse(inspect.isroutine(object())) + self.assertFalse(inspect.isroutine(str())) + # to module + self.assertFalse(inspect.isroutine(mod)) + def test_isclass(self): self.istest(inspect.isclass, 'mod.StupidGit') From 7439bc9818edf72d0c40bffa4c178a1390ec42ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87EL=C4=B0K?= Date: Wed, 1 Apr 2020 00:18:36 +0300 Subject: [PATCH 05/18] New function add in whatsnew --- Doc/whatsnew/3.9.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index c7255b3d417652..956d9979b7b3c6 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -545,6 +545,9 @@ inspect :attr:`inspect.BoundArguments.arguments` is changed from ``OrderedDict`` to regular dict. (Contributed by Inada Naoki in :issue:`36350` and :issue:`39775`.) +Add :func:`inspect.ismethodwrapper` for checking if the object is a method wrapper. +(Contributed by Hakan Çelik in :issue:`29418`.) + ipaddress --------- From 036c1d5d417015bc240176450fa71cb7f70fe65e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 31 Mar 2020 20:53:12 +0000 Subject: [PATCH 06/18] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst diff --git a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst new file mode 100644 index 00000000000000..d6979f2a3159a9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst @@ -0,0 +1 @@ +Fix, return ``True`` if the object is a method-wrapper add new function named ismethodwrapper. Patch by Hakan Çelik. \ No newline at end of file From fb0c9c78d55b301895f8d6e39fcccba35c914252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Thu, 16 Apr 2020 13:51:10 +0300 Subject: [PATCH 07/18] Update 2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst --- .../next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst index d6979f2a3159a9..2cc82daf46195f 100644 --- a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst +++ b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst @@ -1 +1 @@ -Fix, return ``True`` if the object is a method-wrapper add new function named ismethodwrapper. Patch by Hakan Çelik. \ No newline at end of file +Implement :func:`inspect.ismethodwrapper` and :fix:'inspect:isroutine' for cases where methodwrapper is given. Patch by Hakan Çelik. From f88bc536610c7d7397aaaf2bd306940c8d2d83bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Thu, 16 Apr 2020 13:52:31 +0300 Subject: [PATCH 08/18] Update 2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst --- .../next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst index 2cc82daf46195f..39de911e57fc7d 100644 --- a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst +++ b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst @@ -1 +1 @@ -Implement :func:`inspect.ismethodwrapper` and :fix:'inspect:isroutine' for cases where methodwrapper is given. Patch by Hakan Çelik. +Implement :func:`inspect.ismethodwrapper` and :fix:`inspect.isroutine` for cases where methodwrapper is given. Patch by Hakan Çelik. From d61e4b1226b6ec5b68b5cb1e3016ed154ae57984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Thu, 16 Apr 2020 13:53:35 +0300 Subject: [PATCH 09/18] Update 2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst --- .../next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst index 39de911e57fc7d..b188ac3992d5a0 100644 --- a/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst +++ b/Misc/NEWS.d/next/Library/2020-03-31-20-53-11.bpo-29418.8Qa9cQ.rst @@ -1 +1 @@ -Implement :func:`inspect.ismethodwrapper` and :fix:`inspect.isroutine` for cases where methodwrapper is given. Patch by Hakan Çelik. +Implement :func:`inspect.ismethodwrapper` and fix :func:`inspect.isroutine` for cases where methodwrapper is given. Patch by Hakan Çelik. From cc71878bc42fde9d4519348f78d8b3725d85fb44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Sun, 27 Sep 2020 19:39:19 +0300 Subject: [PATCH 10/18] More detail & test --- Doc/library/inspect.rst | 2 +- Doc/whatsnew/3.10.rst | 5 +++++ Doc/whatsnew/3.9.rst | 3 --- Lib/inspect.py | 7 ++++++- Lib/test/test_inspect.py | 24 +++++++++++++++--------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index e8b0674486eb27..a0ae34613e7f17 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -431,7 +431,7 @@ attributes: .. function:: ismethodwrapper(object) - Return ``True`` if the object is a method-wrapper. + Return ``True`` if the type of object is a :class:`~types.MethodWrapperType`. .. function:: isroutine(object) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 806170ede15964..7a80d3a574427e 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1223,6 +1223,9 @@ now call :func:`inspect.get_annotations` to retrieve annotations. This means also now un-stringize stringized annotations. (Contributed by Larry Hastings in :issue:`43817`.) +Add :func:`inspect.ismethodwrapper` for checking if the type of object is a +:class:`~types.MethodWrapperType`. (Contributed by Hakan Çelik in :issue:`29418`.) + linecache --------- @@ -1511,6 +1514,7 @@ Add a :class:`~xml.sax.handler.LexicalHandler` class to the :mod:`xml.sax.handler` module. (Contributed by Jonathan Gossage and Zackery Spytz in :issue:`35018`.) + zipimport --------- Add methods related to :pep:`451`: :meth:`~zipimport.zipimporter.find_spec`, @@ -1520,6 +1524,7 @@ Add methods related to :pep:`451`: :meth:`~zipimport.zipimporter.find_spec`, Add :meth:`~zipimport.zipimporter.invalidate_caches` method. (Contributed by Desmond Cheong in :issue:`14678`.) +======= Optimizations diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index 956d9979b7b3c6..c7255b3d417652 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -545,9 +545,6 @@ inspect :attr:`inspect.BoundArguments.arguments` is changed from ``OrderedDict`` to regular dict. (Contributed by Inada Naoki in :issue:`36350` and :issue:`39775`.) -Add :func:`inspect.ismethodwrapper` for checking if the object is a method wrapper. -(Contributed by Hakan Çelik in :issue:`29418`.) - ipaddress --------- diff --git a/Lib/inspect.py b/Lib/inspect.py index 1d3e41a870e006..bc130851d42f4d 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -510,7 +510,12 @@ def isbuiltin(object): return isinstance(object, types.BuiltinFunctionType) def ismethodwrapper(object): - """return True if the object is a method-wrapper.""" + """Return true if the type of object is a types.MethodWrapperType. + + For example; + + >>> ismethodwrapper(object().__str__) + ... True""" return isinstance(object, types.MethodWrapperType) def isroutine(object): diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index 911e6c7012c09e..db879dd6a5900f 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -44,7 +44,8 @@ # isbuiltin, isroutine, isgenerator, isgeneratorfunction, getmembers, # getdoc, getfile, getmodule, getsourcefile, getcomments, getsource, # getclasstree, getargvalues, formatargvalues, -# currentframe, stack, trace, isdatadescriptor +# currentframe, stack, trace, isdatadescriptor, +# ismethodwrapper # NOTE: There are some additional tests relating to interaction with # zipimport in the test_zipimport_support test module. @@ -93,7 +94,8 @@ class IsTestBase(unittest.TestCase): inspect.ismodule, inspect.istraceback, inspect.isgenerator, inspect.isgeneratorfunction, inspect.iscoroutine, inspect.iscoroutinefunction, - inspect.isasyncgen, inspect.isasyncgenfunction]) + inspect.isasyncgen, inspect.isasyncgenfunction, + inspect.ismethodwrapper]) def istest(self, predicate, exp): obj = eval(exp) @@ -169,6 +171,10 @@ def test_excluding_predicates(self): self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') else: self.assertFalse(inspect.ismemberdescriptor(datetime.timedelta.days)) + self.istest(inspect.ismethodwrapper, "object().__str__") + self.istest(inspect.ismethodwrapper, "object().__eq__") + self.istest(inspect.ismethodwrapper, "object().__repr__") + def test_iscoroutine(self): async_gen_coro = async_generator_function_example(1) @@ -241,33 +247,33 @@ class NotFuture: pass coro.close(); gen_coro.close() # silence warnings def test_isroutine(self): - # to method + # method self.assertTrue(inspect.isroutine(git.argue)) self.assertTrue(inspect.isroutine(mod.custom_method)) self.assertTrue(inspect.isroutine([].count)) - # to function + # function self.assertTrue(inspect.isroutine(mod.spam)) self.assertTrue(inspect.isroutine(mod.StupidGit.abuse)) - # to slot-wrapper + # slot-wrapper self.assertTrue(inspect.isroutine(object.__init__)) self.assertTrue(inspect.isroutine(object.__str__)) self.assertTrue(inspect.isroutine(object.__lt__)) self.assertTrue(inspect.isroutine(int.__lt__)) - # to method-wrapper + # method-wrapper self.assertTrue(inspect.isroutine(object().__init__)) self.assertTrue(inspect.isroutine(object().__str__)) self.assertTrue(inspect.isroutine(object().__lt__)) self.assertTrue(inspect.isroutine((42).__lt__)) - # to method-descriptor + # method-descriptor self.assertTrue(inspect.isroutine(str.join)) self.assertTrue(inspect.isroutine(list.append)) self.assertTrue(inspect.isroutine(''.join)) self.assertTrue(inspect.isroutine([].append)) - # to object + # object self.assertFalse(inspect.isroutine(object)) self.assertFalse(inspect.isroutine(object())) self.assertFalse(inspect.isroutine(str())) - # to module + # module self.assertFalse(inspect.isroutine(mod)) From 303edd446d1f0a474b76a813515026b8ff790be9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Tue, 29 Sep 2020 05:36:50 +0300 Subject: [PATCH 11/18] More test add & update docs --- Doc/library/inspect.rst | 3 +++ Lib/inspect.py | 2 +- Lib/test/test_inspect.py | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index a0ae34613e7f17..7a6dc9c0337d8c 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -433,6 +433,9 @@ attributes: Return ``True`` if the type of object is a :class:`~types.MethodWrapperType`. + These are instances of :class:`~types.MethodWrapperType`, such as :meth:`~object().__str__`, + :meth:`~object().__eq__` and :meth:`~object().__repr__` + .. function:: isroutine(object) diff --git a/Lib/inspect.py b/Lib/inspect.py index bc130851d42f4d..6b3291c9d601d6 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -510,7 +510,7 @@ def isbuiltin(object): return isinstance(object, types.BuiltinFunctionType) def ismethodwrapper(object): - """Return true if the type of object is a types.MethodWrapperType. + """Return true if the object is a method wrapper. For example; diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index db879dd6a5900f..c7bee6c618da56 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -174,6 +174,10 @@ def test_excluding_predicates(self): self.istest(inspect.ismethodwrapper, "object().__str__") self.istest(inspect.ismethodwrapper, "object().__eq__") self.istest(inspect.ismethodwrapper, "object().__repr__") + self.assertFalse(inspect.ismethodwrapper(type)) + self.assertFalse(inspect.ismethodwrapper(int)) + self.assertFalse(inspect.ismethodwrapper(type("AnyClass", (), {}))) + def test_iscoroutine(self): From e80373926952245498c12df813c6c9f917e566fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Sun, 13 Feb 2022 15:04:37 +0300 Subject: [PATCH 12/18] Add type test for isroutine method --- Lib/test/test_inspect.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index c7bee6c618da56..b9b570be659ae6 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -279,7 +279,10 @@ def test_isroutine(self): self.assertFalse(inspect.isroutine(str())) # module self.assertFalse(inspect.isroutine(mod)) - + # type + self.assertFalse(inspect.isroutine(type)) + self.assertFalse(inspect.isroutine(int)) + self.assertFalse(inspect.isroutine(type('some_class', () {}))) def test_isclass(self): self.istest(inspect.isclass, 'mod.StupidGit') From 68537b86e72bad1fcdd29d876e738d5b51b400b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Sun, 13 Feb 2022 15:21:57 +0300 Subject: [PATCH 13/18] Fix syntax error --- Lib/test/test_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_inspect.py b/Lib/test/test_inspect.py index b9b570be659ae6..9e3c77056d70a0 100644 --- a/Lib/test/test_inspect.py +++ b/Lib/test/test_inspect.py @@ -282,7 +282,7 @@ def test_isroutine(self): # type self.assertFalse(inspect.isroutine(type)) self.assertFalse(inspect.isroutine(int)) - self.assertFalse(inspect.isroutine(type('some_class', () {}))) + self.assertFalse(inspect.isroutine(type('some_class', (), {}))) def test_isclass(self): self.istest(inspect.isclass, 'mod.StupidGit') From e6e9f5571ba8341515cb2500c6203bac183dffda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Sun, 13 Feb 2022 15:42:22 +0300 Subject: [PATCH 14/18] Add ismethodwrapper into all --- Lib/inspect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/inspect.py b/Lib/inspect.py index 6b3291c9d601d6..562d1cfb748bae 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -121,6 +121,7 @@ "ismemberdescriptor", "ismethod", "ismethoddescriptor", + "ismethodwrapper", "ismodule", "isroutine", "istraceback", From d7e2f16efed99f1ca39b506d5b78253cd771e6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Tue, 15 Feb 2022 23:41:34 +0300 Subject: [PATCH 15/18] Update Doc/whatsnew/3.10.rst Co-authored-by: Batuhan Taskaya --- Doc/whatsnew/3.10.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 7a80d3a574427e..2755323ef22b1f 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1223,7 +1223,7 @@ now call :func:`inspect.get_annotations` to retrieve annotations. This means also now un-stringize stringized annotations. (Contributed by Larry Hastings in :issue:`43817`.) -Add :func:`inspect.ismethodwrapper` for checking if the type of object is a +Add :func:`inspect.ismethodwrapper` for checking if the type of an object is a :class:`~types.MethodWrapperType`. (Contributed by Hakan Çelik in :issue:`29418`.) linecache From fd03838b766395b1b46df6188bd3ab28fdacb25b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hakan=20=C3=87elik?= Date: Tue, 15 Feb 2022 23:43:05 +0300 Subject: [PATCH 16/18] Update Lib/inspect.py Co-authored-by: Batuhan Taskaya --- Lib/inspect.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Lib/inspect.py b/Lib/inspect.py index 562d1cfb748bae..9c1283ab3734bf 100644 --- a/Lib/inspect.py +++ b/Lib/inspect.py @@ -511,12 +511,7 @@ def isbuiltin(object): return isinstance(object, types.BuiltinFunctionType) def ismethodwrapper(object): - """Return true if the object is a method wrapper. - - For example; - - >>> ismethodwrapper(object().__str__) - ... True""" + """Return true if the object is a method wrapper.""" return isinstance(object, types.MethodWrapperType) def isroutine(object): From f1721b7a0a5527945c8a4a06a9b2843c74d7d3a9 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 16 Feb 2022 14:24:23 +0200 Subject: [PATCH 17/18] Apply suggestions from code review --- Doc/whatsnew/3.10.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 2755323ef22b1f..7add8c74325993 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1514,7 +1514,6 @@ Add a :class:`~xml.sax.handler.LexicalHandler` class to the :mod:`xml.sax.handler` module. (Contributed by Jonathan Gossage and Zackery Spytz in :issue:`35018`.) - zipimport --------- Add methods related to :pep:`451`: :meth:`~zipimport.zipimporter.find_spec`, @@ -1524,7 +1523,6 @@ Add methods related to :pep:`451`: :meth:`~zipimport.zipimporter.find_spec`, Add :meth:`~zipimport.zipimporter.invalidate_caches` method. (Contributed by Desmond Cheong in :issue:`14678`.) -======= Optimizations From 6b627aa432d98a45dd22abf4ba00a42e397cfea4 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Wed, 16 Feb 2022 14:25:55 +0200 Subject: [PATCH 18/18] Update Doc/whatsnew/3.10.rst --- Doc/whatsnew/3.10.rst | 3 --- 1 file changed, 3 deletions(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 7add8c74325993..806170ede15964 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -1223,9 +1223,6 @@ now call :func:`inspect.get_annotations` to retrieve annotations. This means also now un-stringize stringized annotations. (Contributed by Larry Hastings in :issue:`43817`.) -Add :func:`inspect.ismethodwrapper` for checking if the type of an object is a -:class:`~types.MethodWrapperType`. (Contributed by Hakan Çelik in :issue:`29418`.) - linecache ---------