Skip to content
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

Fix #856 by ignoring combining diacritics when computing line length #869

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pycodestyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@
"""
from __future__ import with_statement

import bisect
import inspect
import keyword
import os
import re
import sys
import time
import tokenize
import unicodedata
import warnings
import bisect

try:
from functools import lru_cache
Expand Down Expand Up @@ -296,12 +297,15 @@ def maximum_line_length(physical_line, max_line_length, multiline,
(len(chunks) == 2 and chunks[0] == '#')) and \
len(line) - len(chunks[-1]) < max_line_length - 7:
return
if hasattr(line, 'decode'): # Python 2
# The line could contain multi-byte characters
# Special case: multi-byte chars and combining diacritics
if sys.version_info >= (3,):
line_text = line
else:
try:
length = len(line.decode('utf-8'))
except UnicodeError:
pass
line_text = line.decode('UTF-8')
except UnicodeDecodeError:
line_text = u''
length = sum(not unicodedata.combining(c) for c in line_text)
if length > max_line_length:
return (max_line_length, "E501 line too long "
"(%d > %d characters)" % (length, max_line_length))
Expand Down
4 changes: 4 additions & 0 deletions testsuite/E50.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
('''
''' + ' \
')

#
#: Okay
this = 'é́́́́xá́́́́mplé́́́́ há́́́́s ló́́́́ts ó́́́́f có́́́́mbí́́́́ní́́́́ng dí́́́́á́́́́crí́́́́tí́́́́cs, á́́́́nd thá́́́́t í́́́́s ó́́́́ká́́́́y.'
#: E501 E225 E226
very_long_identifiers=and_terrible_whitespace_habits(are_no_excuse+for_long_lines)
#
Expand Down