Skip to content

Commit

Permalink
practracker: Read unicode files when using Python 2
Browse files Browse the repository at this point in the history
Allow the "practracker" coding best practices checking script to read
unicode files, when using Python 2.

We made the script use unicode literals in 0.4.3.1-alpha, but didn't
change the codec for opening files.

Fixes bug 33374; bugfix on 0.4.3.1-alpha.
  • Loading branch information
teor2345 committed Feb 18, 2020
1 parent a79841f commit 57ff8d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 5 additions & 0 deletions changes/bug33374
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
o Minor bugfixes (coding best practices checks):
- Allow the "practracker" coding best practices checking script to read
unicode files, when using Python 2. We made the script use unicode
literals in 0.4.3.1-alpha, but didn't change the codec for opening files.
Fixes bug 33374; bugfix on 0.4.3.1-alpha.
10 changes: 3 additions & 7 deletions scripts/maint/practracker/practracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from __future__ import print_function
from __future__ import unicode_literals

import os, sys
import codecs, os, sys

import metrics
import util
Expand Down Expand Up @@ -63,12 +63,8 @@

#######################################################

if sys.version_info[0] <= 2:
def open_file(fname):
return open(fname, 'r')
else:
def open_file(fname):
return open(fname, 'r', encoding='utf-8')
def open_file(fname):
return codecs.open(fname, 'r', encoding='utf-8')

def consider_file_size(fname, f):
"""Consider the size of 'f' and yield an FileSizeItem for it.
Expand Down

0 comments on commit 57ff8d4

Please sign in to comment.