Skip to content

Commit 4e93aad

Browse files
committed
Dropping Python 2.7 support
closes #91
1 parent 6163d42 commit 4e93aad

File tree

3 files changed

+9
-42
lines changed

3 files changed

+9
-42
lines changed

fprettify/__init__.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,17 @@
6565
whitespaces
6666
- open files only when needed
6767
"""
68-
from __future__ import (absolute_import, division,
69-
print_function, unicode_literals)
7068
import re
7169
import sys
7270
import logging
7371
import os
7472
import io
7573

76-
# allow for unicode for stdin / stdout, it's a mess
77-
try:
78-
# python 3
79-
sys.stdin = io.TextIOWrapper(
80-
sys.stdin.detach(), encoding='UTF-8', line_buffering=True)
81-
sys.stdout = io.TextIOWrapper(
82-
sys.stdout.detach(), encoding='UTF-8', line_buffering=True)
83-
except AttributeError: # pragma: no cover
84-
# python 2
85-
import codecs
86-
utf8_reader = codecs.getreader('UTF-8')
87-
utf8_writer = codecs.getwriter('UTF-8')
88-
sys.stdin = utf8_reader(sys.stdin)
89-
sys.stdout = utf8_writer(sys.stdout)
74+
sys.stdin = io.TextIOWrapper(
75+
sys.stdin.detach(), encoding='UTF-8', line_buffering=True)
76+
sys.stdout = io.TextIOWrapper(
77+
sys.stdout.detach(), encoding='UTF-8', line_buffering=True)
78+
9079

9180
from .fparse_utils import (VAR_DECL_RE, OMP_COND_RE,
9281
InputStream, CharFilter,

fprettify/fparse_utils.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
"""This is a collection of Fortran parsing utilities."""
2121

22-
from __future__ import (absolute_import, division,
23-
print_function, unicode_literals)
2422
import re
2523
from collections import deque
2624

@@ -123,10 +121,6 @@ def update(self, string, filter_comments=True, filter_strings=True,
123121
def __iter__(self):
124122
return self
125123

126-
def next(self): # pragma: no cover
127-
""" Python 2 compatibility """
128-
return self.__next__()
129-
130124
def __next__(self):
131125

132126
pos, char = next(self._it)

fprettify/tests/__init__.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,8 @@
3333
import subprocess
3434
import inspect
3535

36-
# allow unicode for stdin / stdout, it's a mess
37-
try:
38-
# python 3
39-
sys.stderr = io.TextIOWrapper(
40-
sys.stderr.detach(), encoding='UTF-8', line_buffering=True)
41-
42-
except AttributeError: # pragma: no cover
43-
# python 2
44-
import codecs
45-
utf8_writer = codecs.getwriter('UTF-8')
46-
sys.stderr = utf8_writer(sys.stderr)
36+
sys.stderr = io.TextIOWrapper(
37+
sys.stderr.detach(), encoding='UTF-8', line_buffering=True)
4738

4839
import fprettify
4940
from fprettify.fparse_utils import FprettifyParseException, FprettifyInternalException
@@ -76,9 +67,7 @@ def eprint(*args, **kwargs):
7667
Print to stderr - to print output compatible with default unittest output.
7768
"""
7869

79-
print(*args, file=sys.stderr, **kwargs)
80-
sys.stderr.flush() # python 2 print does not have flush argument
81-
70+
print(*args, file=sys.stderr, flush=True, **kwargs)
8271

8372
class FPrettifyTestCase(unittest.TestCase):
8473
"""
@@ -943,12 +932,7 @@ def test_result(path, info):
943932

944933
# not sure why this even works, using "test something" (with a space) as function name...
945934
# however it gives optimal test output
946-
try:
947-
testmethod.__name__ = ("test " + joinpath(fpath, ffile))
948-
except TypeError: # pragma: no cover
949-
# need to encode in python 2 since we are using unicode strings
950-
testmethod.__name__ = (
951-
"test " + joinpath(fpath, ffile)).encode('utf-8')
935+
testmethod.__name__ = ("test " + joinpath(fpath, ffile))
952936

953937
setattr(testcase, testmethod.__name__, testmethod)
954938

0 commit comments

Comments
 (0)