Menu

#348 DeprecationWarning: 'U' mode is deprecated

closed-fixed
nobody
None
5
2020-03-03
2018-08-09
Hugo
No

I'm not using docutils directly, but it's used by a dependency. There will be an easier way to reproduce it, this is how I'm getting it with Python 3.7:

git clone https://github.com/python-pillow/Pillow && cd Pillow
pip install -e .
pip install pyroma
python Tests/test_pyroma.py

Results in:

<snip other warnings>
/usr/local/lib/python3.7/site-packages/docutils/io.py:245: DeprecationWarning: 'U' mode is deprecated
  self.source = open(source_path, mode, **kwargs)
.
----------------------------------------------------------------------
Ran 1 test in 0.520s

OK

It is caused by the U in the mode here:

class FileInput(Input):

    """
    Input for single, simple file-like objects.
    """
    def __init__(self, source=None, source_path=None,
                 encoding=None, error_handler='strict',
                 autoclose=True, mode='rU', **kwargs):

Since Python 3.4, the 'U' universal newlines mode has been deprecated.
https://docs.python.org/3.4/library/functions.html#open

From Python 3.0-3.3, it has been labelled "for backwards compatibility; unneeded for new code".
https://docs.python.org/3.0/library/functions.html#open

Related

Bugs: #348

Discussion

  • Hugo

    Hugo - 2018-08-09

    Python 3.7.0
    docutils 0.14

    Smaller test case:

    import pyroma
    data = pyroma.projectdata.get_data(".")
    rating = pyroma.ratings.rate(data)
    

    And run with deprecation warnings enabled:

    $ pip install pyroma
    $ python -W default::DeprecationWarning pyroma-test.py
    <snip other warnings>
    /usr/local/lib/python3.7/site-packages/docutils/io.py:245: DeprecationWarning: 'U' mode is deprecated
    
     
  • Stéphane Blondon

    It's probably a problem to remove it because docutils still supports python2.

     
    • engelbert gruber

      Shouldn't it then be handled by 2to3 ?

      "Stéphane Blondon" stephaneb@users.sourceforge.net schrieb am Sa., 11.
      Aug. 2018, 14:50:

      It's probably a problem to remove it because docutils still supports
      python2.


      Status: open
      Group: Default
      Created: Thu Aug 09, 2018 09:02 AM UTC by Hugo
      Last Updated: Thu Aug 09, 2018 09:14 AM UTC
      Owner: nobody

      I'm not using docutils directly, but it's used by a dependency. There will
      be an easier way to reproduce it, this is how I'm getting it with Python
      3.7:

      git clone https://github.com/python-pillow/Pillow && cd Pillow
      pip install -e .
      pip install pyroma
      python Tests/test_pyroma.py

      Results in:

      <snip other="" warnings="">
      /usr/local/lib/python3.7/site-packages/docutils/io.py:245: DeprecationWarning: 'U' mode is deprecated
      self.source = open(source_path, mode, **kwargs)
      .</snip>


      Ran 1 test in 0.520s

      OK

      It is caused by the U in the mode here:

      class FileInput(Input):

      """    Input for single, simple file-like objects.    """
      def __init__(self, source=None, source_path=None,
                   encoding=None, error_handler='strict',
                   autoclose=True, mode='rU', **kwargs):
      

      Since Python 3.4, the 'U' universal newlines mode has been deprecated.
      https://docs.python.org/3.4/library/functions.html#open

      From Python 3.0-3.3, it has been labelled "for backwards compatibility;
      unneeded for new code".
      https://docs.python.org/3.0/library/functions.html#open


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/docutils/bugs/348/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      Bugs: #348

      • Ovidiu Ciule

        Ovidiu Ciule - 2018-08-20

        2to3 does not have a fixer for this issue, as it was written to fix issues when migrating from py2.x to 3.0 and using the "U" mode started throwing DeprecatedWarning only in 3.4.

        It's possible to write a custom fixer, or course.

         
  • Hugo

    Hugo - 2018-08-20

    Maybe something along the lines of this?

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

     
    • Hugo

      Hugo - 2018-09-08

      I've created a patch with this suggestion:

      https://sourceforge.net/p/docutils/patches/144/

       
  • engelbert gruber

    • status: open --> closed-fixed
     
  • engelbert gruber

    thanks and all the best

     

Log in to post a comment.

MongoDB Logo MongoDB