Menu

#144 Remove DeprecationWarning in Python >= 3.4

None
closed-fixed
nobody
None
5
2018-11-21
2018-09-08
Hugo
No

Fixes https://sourceforge.net/p/docutils/bugs/348/.

Currently there's a DeprecationWarning when using Python >= 3.4:

/usr/local/lib/python3.7/site-packages/docutils/io.py:245: DeprecationWarning: 'U' mode is deprecated

The attached patch uses mode r for Python >= 3.4, otherwise rU:

mode = 'r' if sys.version_info >= (3, 4) else 'rU'

Tests pass locally for Python 2.7.15 and Python 3.7.0:

71% [hugo:/tmp/docutils-code/docutils] trunk(1)  python2 test/alltests.py
Testing Docutils 0.15b.dev with Python 2.7.15 on 2018-09-08 at 15:30:43
OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
Working directory: /private/tmp/docutils-code/docutils/test
Docutils package: /private/tmp/docutils-code/docutils/docutils
............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 1388 tests in 9.967s

OK
Elapsed time: 12.112 seconds
[hugo:/tmp/docutils-code/docutils] trunk(1) 12s  python3 test3/alltests.py
Testing Docutils 0.15b.dev with Python 3.7.0 on 2018-09-08 at 15:31:06
OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
Working directory: /private/tmp/docutils-code/docutils/test3
Docutils package: /private/tmp/docutils-code/docutils/build/lib/docutils
...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 1391 tests in 8.363s

OK
Elapsed time: 9.726 seconds
1 Attachments

Discussion

  • engelbert gruber

    ... and a test that fails before and passes after applying ... :-)

     
  • Hugo

    Hugo - 2018-09-09

    Here's the patch with a test that fails on Python 3.7 before, and passes after.

    Before:

    71% [hugo:/private/tmp/docutils-code/docutils] trunk(1) 14s  python2 test/alltests.py && python3 setup.py build && python3 test3/alltests.py
    Testing Docutils 0.15b.dev with Python 2.7.15 on 2018-09-09 at 13:40:54
    OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
    Working directory: /private/tmp/docutils-code/docutils/test
    Docutils package: /private/tmp/docutils-code/docutils/docutils
    .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    ----------------------------------------------------------------------
    Ran 1389 tests in 10.110s
    
    OK
    Elapsed time: 12.251 seconds
    running build
    running build_py
    build_py_2to3
    copying docutils/io.py -> build/lib/docutils
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    copy/convert test suite
    running build_scripts
    running build_data
    Testing Docutils 0.15b.dev with Python 3.7.0 on 2018-09-09 at 13:41:07
    OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
    Working directory: /private/tmp/docutils-code/docutils/test3
    Docutils package: /private/tmp/docutils-code/docutils/build/lib/docutils
    ...................................................................................................................F............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    ======================================================================
    FAIL: test_deprecation_warning (test_io.InputTests)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/private/tmp/docutils-code/docutils/test3/test_io.py", line 149, in test_deprecation_warning
        list(v.category for v in w))
    AssertionError: 1 != 0 : Expected no warnings, got [<class 'DeprecationWarning'>]
    
    ----------------------------------------------------------------------
    Ran 1392 tests in 8.471s
    
    FAILED (failures=1)
    Elapsed time: 10.014 seconds
    

    After:

    66% [hugo:/private/tmp/docutils-code/docutils] trunk(2) 23s 1  python2 test/alltests.py && python3 setup.py build && python3 test3/alltests.py
    Testing Docutils 0.15b.dev with Python 2.7.15 on 2018-09-09 at 13:42:30
    OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
    Working directory: /private/tmp/docutils-code/docutils/test
    Docutils package: /private/tmp/docutils-code/docutils/docutils
    .............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    ----------------------------------------------------------------------
    Ran 1389 tests in 9.531s
    
    OK
    Elapsed time: 11.542 seconds
    running build
    running build_py
    build_py_2to3
    copying docutils/io.py -> build/lib/docutils
    Skipping optional fixer: buffer
    Skipping optional fixer: idioms
    Skipping optional fixer: set_literal
    Skipping optional fixer: ws_comma
    copy/convert test suite
    running build_scripts
    running build_data
    Testing Docutils 0.15b.dev with Python 3.7.0 on 2018-09-09 at 13:42:42
    OS: Darwin 17.7.0 Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64 (darwin, Darwin-17.7.0-x86_64-i386-64bit)
    Working directory: /private/tmp/docutils-code/docutils/test3
    Docutils package: /private/tmp/docutils-code/docutils/build/lib/docutils
    ................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
    ----------------------------------------------------------------------
    Ran 1392 tests in 8.179s
    
    OK
    Elapsed time: 9.477 seconds
    
     
  • Günter Milde

    Günter Milde - 2018-11-21
    • status: open --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2018-11-21

    Applied by grubert in [r8228]

     

    Related

    Commit: [r8228]


Log in to post a comment.