classification
Title: [EASY] test_docxmlrpc fails when run with -Werror
Type: Stage: resolved
Components: Tests, XML Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: niconoe, vstinner, xtreak, yselivanov
Priority: normal Keywords: easy, patch

Created on 2018-06-20 09:56 by vstinner, last changed 2018-07-16 09:03 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7847 merged niconoe, 2018-06-21 14:38
PR 8294 merged miss-islington, 2018-07-16 08:49
Messages (8)
msg320043 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-20 09:56
Ok, but notice the two warnings:

vstinner@apu$ ./python -m test test_docxmlrpc
Run tests sequentially
0:00:00 load avg: 1.19 [1/1] test_docxmlrpc
/home/vstinner/prog/python/master/Lib/xmlrpc/server.py:791: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
  formatvalue=self.formatvalue)
/home/vstinner/prog/python/master/Lib/xmlrpc/server.py:784: DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
  formatvalue=self.formatvalue

== Tests result: SUCCESS ==

1 test OK.

Total duration: 2 sec 698 ms
Tests result: SUCCESS


Fail:

vstinner@apu$ ./python -Werror -m test -v test_docxmlrpc 
test_annotations (test.test_docxmlrpc.DocXMLRPCHTTPGETServer)
Test that annotations works as expected ... ----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 45060)
Traceback (most recent call last):
  File "/home/vstinner/prog/python/master/Lib/socketserver.py", line 313, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/home/vstinner/prog/python/master/Lib/socketserver.py", line 344, in process_request
    self.finish_request(request, client_address)
  File "/home/vstinner/prog/python/master/Lib/socketserver.py", line 357, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/vstinner/prog/python/master/Lib/socketserver.py", line 717, in __init__
    self.handle()
  File "/home/vstinner/prog/python/master/Lib/http/server.py", line 426, in handle
    self.handle_one_request()
  File "/home/vstinner/prog/python/master/Lib/http/server.py", line 414, in handle_one_request
    method()
  File "/home/vstinner/prog/python/master/Lib/xmlrpc/server.py", line 936, in do_GET
    response = self.server.generate_html_documentation().encode('utf-8')
  File "/home/vstinner/prog/python/master/Lib/xmlrpc/server.py", line 910, in generate_html_documentation
    methods
  File "/home/vstinner/prog/python/master/Lib/xmlrpc/server.py", line 828, in docserver
    contents.append(self.docroutine(value, key, funcs=fdict))
  File "/home/vstinner/prog/python/master/Lib/xmlrpc/server.py", line 791, in docroutine
    formatvalue=self.formatvalue)
  File "/home/vstinner/prog/python/master/Lib/inspect.py", line 1225, in formatargspec
    stacklevel=2)
DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
----------------------------------------
ERROR
(...)
== Tests result: FAILURE ==

1 test failed:
    test_docxmlrpc

Total duration: 3 sec 234 ms
Tests result: FAILURE



It seems like the fix is explained in the error message:

Lib/xmlrpc/server.py, line 791, in docroutine():

DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
msg320139 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-06-21 05:55
Slightly off topic but while trying to look at the code I can see a space between function name and parenthesis as below. It's not an invalid syntax but it's mentioned as a pet peeve in PEP 8 to not to have space between function name and parenthesis. I did a simple grep and I could some places where even function definitions have spaces as below. It's a trivial thing but just wanted to post it here and might seem like an invalid syntax for someone new fixing it.

# Lib/xmlrpc/server.py

argspec = inspect.formatargspec (

# simple grep and manual scanning with `rg '\w+ \(' | grep -v -E 'if|while|for|except|return' | grep '.py' | less`

Tools/gdb/libpython.py:    def __init__ (self, gdbval):
Tools/gdb/libpython.py:    def to_string (self):
Tools/gdb/libpython.py:def register (obj):
Tools/gdb/libpython.py:register (gdb.current_objfile ())
Tools/gdb/libpython.py:        gdb.Command.__init__ (self,
Tools/gdb/libpython.py:        gdb.Command.__init__ (self,
Tools/gdb/libpython.py:        gdb.Command.__init__ (self,
Tools/gdb/libpython.py:        gdb.Command.__init__ (self,
Tools/gdb/libpython.py:        gdb.Command.__init__ (self,

# Relevant PEP 8 section : https://www.python.org/dev/peps/pep-0008/#pet-peeves

> Immediately before the open parenthesis that starts the argument list of a function call:
> Yes: spam(1)
> No:  spam (1)


Also I think it will be good if a deprecation is made then it has to run the test suite with `-Werror` so that the deprecations are fixed which is slightly subjective though where deprecations are reverted back in a future version for reasons like easy 2to3 porting.

Thanks much for these easy issues and I hope someone takes it up.
msg320187 - (view) Author: Nicolas Noé (niconoe) * Date: 2018-06-21 14:18
I'm willing to try solving this!
msg321535 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-12 10:30
> Slightly off topic but while trying to look at the code I can see a space between function name and parenthesis as below. (...)

Usually we don't accept changes which only changes the coding style. One reason is to keep a simple history in Git.
msg321717 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 08:46
New changeset 35c0809158be7feae4c4f877a08b93baea2d8291 by Victor Stinner (Nicolas Noé) in branch 'master':
bpo-33911: Fixed deprecation warning in xmlrpc.server (GH-7847)
https://github.com/python/cpython/commit/35c0809158be7feae4c4f877a08b93baea2d8291
msg321718 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 08:53
Python 3.7 is affected as well:

vstinner@apu$ ./python -Werror -m test test_docxmlrpc
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 46636)
Traceback (most recent call last):
  (...)
  File "/home/vstinner/prog/python/3.7/Lib/xmlrpc/server.py", line 828, in docserver
    contents.append(self.docroutine(value, key, funcs=fdict))
  File "/home/vstinner/prog/python/3.7/Lib/xmlrpc/server.py", line 791, in docroutine
    formatvalue=self.formatvalue)
  File "/home/vstinner/prog/python/3.7/Lib/inspect.py", line 1225, in formatargspec
    stacklevel=2)
DeprecationWarning: `formatargspec` is deprecated since Python 3.5. Use `signature` and the `Signature` object directly
----------------------------------------
Warning -- threading._dangling was modified by test_docxmlrpc
  Before: <_weakrefset.WeakSet object at 0x7fc84da8f810>
  After:  <_weakrefset.WeakSet object at 0x7fc84da8f538> 
test test_docxmlrpc failed -- multiple errors occurred; run in verbose mode for details
test_docxmlrpc failed


I generated PR 8294 backport to fix Python 3.7 as well. Since the HTML output is unchanged, IMHO it's safe to backport the change.

In the documentation, inspect.formatargspec() is also deprecated in Python 3.6, but the code doesn't emit a DeprecationWarning. I don't think that it's worth it to backport the change to Python 3.6.
msg321720 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 09:02
New changeset bbddd667a9087f5cfb9e8f9d81fb6d2f75465ba1 by Victor Stinner (Miss Islington (bot)) in branch '3.7':
bpo-33911: Fixed deprecation warning in xmlrpc.server (GH-7847) (GH-8294)
https://github.com/python/cpython/commit/bbddd667a9087f5cfb9e8f9d81fb6d2f75465ba1
msg321721 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-07-16 09:03
Nicolas Noé: Thank you for your change! I merged it in master, and backported it to Python 3.7.
History
Date User Action Args
2018-07-16 09:03:25vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg321721

stage: patch review -> resolved
2018-07-16 09:02:34vstinnersetmessages: + msg321720
2018-07-16 08:53:32vstinnersetmessages: + msg321718
versions: + Python 3.7
2018-07-16 08:49:30miss-islingtonsetpull_requests: + pull_request7828
2018-07-16 08:46:17vstinnersetmessages: + msg321717
2018-07-12 10:30:37vstinnersetmessages: + msg321535
2018-06-21 14:38:10niconoesetkeywords: + patch
stage: patch review
pull_requests: + pull_request7457
2018-06-21 14:18:03niconoesetnosy: + niconoe
messages: + msg320187
2018-06-21 05:55:23xtreaksetnosy: + xtreak
messages: + msg320139
2018-06-20 10:09:18serhiy.storchakasetnosy: + yselivanov
2018-06-20 09:57:05vstinnersetcomponents: + Tests, XML
2018-06-20 09:56:55vstinnercreate