New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded site.py emits « DeprecationWarning: 'U' mode is deprecated » with python 3.5.4 and 3.6.4 #1120

Open
rhertzog opened this Issue Jan 9, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@rhertzog

rhertzog commented Jan 9, 2018

I often run my unit tests with warnings enabled to ensure that my code is future-proof and since a few weeks (likely since my Debian sid system switched to python 3.5.4 and 3.6.4) those tests are failing with errors like this one:

  File "/home/rhertzog/deb/core/distro-tracker/.tox/py36-django111-no-warnings/lib/python3.6/site.py", line 165, in addpackage
    f = open(fullname, "rU")
DeprecationWarning: 'U' mode is deprecated

The site.py provided in python3.6 does not have this flag, hence I tracked this down to the site.py embedded in virtualenv (on which tox relies to run the tests in a isolated manner).

rhertzog added a commit to rhertzog/distro-tracker that referenced this issue Jan 9, 2018

tox: ignore warnings coming from site.py
Latest python versions generate warnings with the site.py embedded in
virtualenv: pypa/virtualenv#1120
@mjpieters

This comment has been minimized.

Show comment
Hide comment
@mjpieters

mjpieters Mar 16, 2018

Even worse, you can't run in 'error' mode when using a virtualenv:

$ bin/python3.7 -W error - c '[(yield i) for i in range(3)]'  # demonstrate deprecation turned into syntax error in 3.7
Traceback (most recent call last):
  File ".../python-3.7/lib/python3.7/site.py", line 703, in <module>
    main()
  File ".../python-3.7/lib/python3.7/site.py", line 686, in main
    paths_in_sys = virtual_addsitepackages(paths_in_sys)
  File ".../python-3.7/lib/python3.7/site.py", line 644, in virtual_addsitepackages
    return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
  File ".../python-3.7/lib/python3.7/site.py", line 282, in addsitepackages
    addsitedir(sitedir, known_paths)
  File ".../python-3.7/lib/python3.7/site.py", line 204, in addsitedir
    addpackage(sitedir, name, known_paths)
  File ".../python-3.7/lib/python3.7/site.py", line 165, in addpackage
    f = open(fullname, "rU")
DeprecationWarning: 'U' mode is deprecated

You have to enable warnings in the main script instead, which means syntax issues won't be caught, you have to use exec instead:

$ bin/python3.7 -c "import warnings; warnings.simplefilter('error');exec('''[(yield i) for i in range(3)]''')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1
SyntaxError: 'yield' inside list comprehension

mjpieters commented Mar 16, 2018

Even worse, you can't run in 'error' mode when using a virtualenv:

$ bin/python3.7 -W error - c '[(yield i) for i in range(3)]'  # demonstrate deprecation turned into syntax error in 3.7
Traceback (most recent call last):
  File ".../python-3.7/lib/python3.7/site.py", line 703, in <module>
    main()
  File ".../python-3.7/lib/python3.7/site.py", line 686, in main
    paths_in_sys = virtual_addsitepackages(paths_in_sys)
  File ".../python-3.7/lib/python3.7/site.py", line 644, in virtual_addsitepackages
    return addsitepackages(known_paths, sys_prefix=sys.real_prefix)
  File ".../python-3.7/lib/python3.7/site.py", line 282, in addsitepackages
    addsitedir(sitedir, known_paths)
  File ".../python-3.7/lib/python3.7/site.py", line 204, in addsitedir
    addpackage(sitedir, name, known_paths)
  File ".../python-3.7/lib/python3.7/site.py", line 165, in addpackage
    f = open(fullname, "rU")
DeprecationWarning: 'U' mode is deprecated

You have to enable warnings in the main script instead, which means syntax issues won't be caught, you have to use exec instead:

$ bin/python3.7 -c "import warnings; warnings.simplefilter('error');exec('''[(yield i) for i in range(3)]''')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "<string>", line 1
SyntaxError: 'yield' inside list comprehension
@mjpieters

This comment has been minimized.

Show comment
Hide comment
@mjpieters

mjpieters Mar 16, 2018

I note that Python itself fixed this for Python 3.1, in 2011: python/cpython@4e86d5b

mjpieters commented Mar 16, 2018

I note that Python itself fixed this for Python 3.1, in 2011: python/cpython@4e86d5b

@mjpieters mjpieters referenced a pull request that will close this issue Mar 16, 2018

Open

Remove deprecated Universal mode #1148

duncanmmacleod added a commit to duncanmmacleod/virtualenv that referenced this issue Jul 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment