Opened 4 years ago

Closed 4 years ago

#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):



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.

Change History (6)

comment:1 Changed 4 years ago 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 4 years ago by jsonesen

  • Owner set to jsonesen

comment:3 Changed 4 years ago by jsonesen

Do you think that this is a case of needing to add logic for handling the unicode literal import?

Version 0, edited 4 years ago by jsonesen (next)

comment:4 Changed 4 years ago by jsonesen

  • Review URL(s) modified (diff)

comment:6 Changed 4 years ago by sebastian

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.