Opened on 05/17/2016 at 01:34:06 PM

Closed on 06/03/2016 at 09:25:57 AM

#4044 closed defect (fixed)

flake8-abp doesn't recognize "from __future__ import unicode_literals"

Reported by: sebastian Assignee: jsonesen
Priority: P3 Milestone:
Module: Sitescripts Keywords:
Cc: jsonesen, kvas Blocked By:
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://codereview.adblockplus.org./29342824/

Description

Background

flake8 is a Python code quality checker which we recently started to use along our own extension flake8-abp. One of the things flake8-abp does is making sure that string literals comply to our coding style, by comparing them to the output of repr() in Python 2, or ascii() in Python 3. However, the current implementation doesn't consider from __future__ import unicode_literals, which if given at the top of the script, causes string literals (without b prefix) to be interpreted as unicode strings, just like in Python 3.

How to reproduce

Run flake8 (using Python 2 and with flake8-abp installed) on following script:

from __future__ import unicode_literals


foo = '\u1234'

Observed behaviour

flake8 outputs following warning:

stdin:4:7: A110 string literal doesn't match repr()

That is because since from __future__ import unicode_literals is ignored the string is interpreted as a byte string where \u has no special meaning and therefore repr('\u1234') returns '\\u1234'.

Expected behaviour

If from __future__ import unicode_literals is used in the file, flake8-abp should consider all string literals (without b) prefix unicode strings, and shouldn't throw a warning in the example above.

Attachments (0)

Change History (6)

comment:1 Changed on 05/17/2016 at 01:34:21 PM by sebastian

  • Summary changed from flak8-abp doesn't recognize "from __future__ import unicode_literals" to flake8-abp doesn't recognize "from __future__ import unicode_literals"

comment:2 Changed on 05/18/2016 at 09:57:42 PM by jsonesen

  • Owner set to jsonesen

comment:3 Changed on 05/19/2016 at 08:08:37 PM by jsonesen

Do you think that it makes sense to add the logic for handling the import to the 'check_quotes' method that raises the exception?

Last edited on 05/19/2016 at 08:15:20 PM by jsonesen

comment:4 Changed on 05/19/2016 at 11:49:07 PM by jsonesen

  • Review URL(s) modified (diff)

comment:5 Changed on 06/03/2016 at 09:25:11 AM by abpbot

comment:6 Changed on 06/03/2016 at 09:25:57 AM by sebastian

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

Add Comment

Modify Ticket

Change Properties
Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from jsonesen.
 
Note: See TracTickets for help on using tickets.