Code

Opened 21 months ago

Closed 19 months ago

Last modified 12 months ago

#19204 closed Bug (fixed)

Python2-style exception syntax is still used in django.utils.unittest (and should be updated)

Reported by: garrison Owned by: aaugustin
Component: Python 3 Version: 1.5-alpha-1
Severity: Release blocker Keywords: py3k
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Installing the Django 1.5a1 package through pip on python 3.2 shows some SyntaxError warnings, due to using python2-style syntax for catching exceptions:

/tmp/venv/bin$ ./pip-3.2 install https://www.djangoproject.com/download/1.5a1/tarball/
Downloading/unpacking https://www.djangoproject.com/download/1.5a1/tarball/
  Downloading  (7.7MB): 7.7MB downloaded
  Cannot determine compression type for file /tmp/pip-6_1a4e-unpack/tarball.ksh
  Running setup.py egg_info for package from https://www.djangoproject.com/download/1.5a1/tarball/
    
    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: Django
  Running setup.py install for Django
    changing mode of build/scripts-3.2/django-admin.py from 644 to 755
      File "/tmp/venv/lib/python3.2/site-packages/django/utils/unittest/loader.py", line 92
        except Exception, e:
                        ^
    SyntaxError: invalid syntax
    
      File "/tmp/venv/lib/python3.2/site-packages/django/utils/unittest/case.py", line 327
        except SkipTest, e:
                       ^
    SyntaxError: invalid syntax
    
      File "/tmp/venv/lib/python3.2/site-packages/django/utils/unittest/main.py", line 153
        except getopt.error, msg:
                           ^
    SyntaxError: invalid syntax
    
      File "/tmp/venv/lib/python3.2/site-packages/django/utils/unittest/suite.py", line 141
        except Exception, e:
                        ^
    SyntaxError: invalid syntax
    
    
    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of /tmp/venv/bin/django-admin.py to 755
Successfully installed Django
Cleaning up...

It's not clear to me why these files were not updated with the new exception syntax, but I've attached a patch that does just that.

Attachments (1)

0001-py3k-Use-python3-syntax-for-exceptions-in-django.uti.patch (6.2 KB) - added by garrison 21 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 21 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

The backport of unittest2 is only there for Python 2.6.

I avoid modifying vendored library unless I absolutely need to.

I wasn't aware it would trigger warnings during installation.

comment:2 Changed 20 months ago by ptone

  • Component changed from Testing framework to Python 3
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug

We are not alone here

https://github.com/kennethreitz/requests/issues/738

I tried a really quick warnings.filterwarnings but didn't work on my first attempt, but I think that route may still bear fruit

I agree that we should not be patching the vendored unittest here - this may be a bug in the way py3 packaging and the way it handles split projects with the bytecompiling done at install.

comment:3 Changed 19 months ago by aaugustin

  • Severity changed from Normal to Release blocker

Eventually I've changed my mind on this.

There are only a few except statements to change. And the backport of unittest2 will go away as soon as we drop support for Python 2.6.

If we agree to make this change, let's do it before 1.5 final.

Last edited 19 months ago by aaugustin (previous) (diff)

comment:4 Changed 19 months ago by aaugustin

  • Owner changed from nobody to aaugustin

comment:5 Changed 19 months ago by claudep

The required changes are really minor, go for it!

comment:6 Changed 19 months ago by Florian Apolloner <florian@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 4a71b842662162e0892a9269179421ff2191adba:

Fixed #19204 -- Replaced python2-style exception syntax.

Thanks to garrison for the report and patch.

comment:7 Changed 19 months ago by Florian Apolloner <florian@…>

In ef98ae2910a6b5c86e1e0b003110455778e63324:

[1.5.X] Fixed #19204 -- Replaced python2-style exception syntax.

Thanks to garrison for the report and patch.

Backport of 4a71b842662162e0892a9269179421ff2191adba from master

comment:8 Changed 12 months ago by Aymeric Augustin <aymeric.augustin@…>

In 7f264e02f4480c49d1440be882416a10951c2165:

Fixed #20680 -- Deprecated django.utils.unittest.

Refs #19204.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.