Skip to content

gh-92266: reindent.py: Add allowlist for files with tabs #135984

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions Tools/patchcheck/reindent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
# A specified newline to be used in the output (set by --newline option)
spec_newline = None

ALLOWLIST_TABS = {
"Tools/c-analyzer/cpython/_parser.py",
}


def usage(msg=None):
if msg is None:
Expand Down Expand Up @@ -125,7 +129,7 @@ def check(file):
return
try:
with open(file, encoding=encoding) as f:
r = Reindenter(f)
r = Reindenter(f, file)
except IOError as msg:
errprint("%s: I/O Error: %s" % (file, str(msg)))
return
Expand Down Expand Up @@ -173,7 +177,7 @@ def _rstrip(line, JUNK='\n \t'):

class Reindenter:

def __init__(self, f):
def __init__(self, f, filename=None):
self.find_stmt = 1 # next token begins a fresh stmt?
self.level = 0 # current indent level

Expand All @@ -183,8 +187,16 @@ def __init__(self, f):
# File lines, rstripped & tab-expanded. Dummy at start is so
# that we can use tokenize's 1-based line numbering easily.
# Note that a line is all-blank iff it's "\n".
self.lines = [_rstrip(line).expandtabs() + "\n"
for line in self.raw]
self.lines = [
(
_rstrip(line)
if filename in ALLOWLIST_TABS
else _rstrip(line).expandtabs()
)
+ "\n"
for line in self.raw
]

self.lines.insert(0, None)
self.index = 1 # index into self.lines of next line

Expand Down
Loading