Skip to content

Commit e1d71c5

Browse files
committed
Remove old py2 compat code
1 parent 3194e0a commit e1d71c5

File tree

7 files changed

+18
-55
lines changed

7 files changed

+18
-55
lines changed

sphinx_automodapi/automodapi.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class are included in the generated documentation. Defaults to ``False``.
101101
# actually built.
102102

103103
import inspect
104-
import io
105104
import os
106105
import re
107106
import sys
@@ -112,11 +111,6 @@ class are included in the generated documentation. Defaults to ``False``.
112111

113112
__all__ = []
114113

115-
if sys.version_info[0] == 3:
116-
text_type = str
117-
else:
118-
text_type = unicode # noqa
119-
120114
automod_templ_modheader = """
121115
{modname} {pkgormod}
122116
{modhds}{pkgormodhds}
@@ -377,14 +371,14 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
377371
if app.config.automodapi_writereprocessed:
378372
# sometimes they are unicode, sometimes not, depending on how
379373
# sphinx has processed things
380-
if isinstance(newsourcestr, text_type):
374+
if isinstance(newsourcestr, str):
381375
ustr = newsourcestr
382376
else:
383377
ustr = newsourcestr.decode(app.config.source_encoding)
384378

385379
if docname is None:
386-
with io.open(os.path.join(app.srcdir, 'unknown.automodapi'),
387-
'a', encoding='utf8') as f:
380+
with open(os.path.join(app.srcdir, 'unknown.automodapi'),
381+
'a', encoding='utf8') as f:
388382
f.write(u'\n**NEW DOC**\n\n')
389383
f.write(ustr)
390384
else:
@@ -394,8 +388,8 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
394388
filename = docname + os.path.splitext(env.doc2path(docname))[1]
395389
filename += '.automodapi'
396390

397-
with io.open(os.path.join(app.srcdir, filename), 'w',
398-
encoding='utf8') as f:
391+
with open(os.path.join(app.srcdir, filename), 'w',
392+
encoding='utf8') as f:
399393
f.write(ustr)
400394

401395
return newsourcestr

sphinx_automodapi/automodsumm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class members that are inherited from a base class. This value can be
8787
import inspect
8888
import os
8989
import re
90-
import io
9190

9291
from sphinx.util import logging
9392
from sphinx.ext.autosummary import Autosummary
@@ -312,7 +311,7 @@ def automodsumm_to_autosummary_lines(fn, app):
312311

313312
fullfn = os.path.join(app.builder.env.srcdir, fn)
314313

315-
with io.open(fullfn, encoding='utf8') as fr:
314+
with open(fullfn, encoding='utf8') as fr:
316315
# Note: we use __name__ here instead of just writing the module name in
317316
# case this extension is bundled into another package
318317
from . import automodapi

sphinx_automodapi/tests/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Licensed under a 3-clause BSD style license - see LICENSE.rst
33

44
import os
5-
import sys
65
from copy import deepcopy
76

87
from sphinx.cmd.build import build_main
@@ -13,8 +12,8 @@
1312

1413

1514
intersphinx_mapping = {
16-
'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None)
17-
}
15+
'python': ('https://docs.python.org/3/', None)
16+
}
1817

1918
DEFAULT_CONF = {'source_suffix': '.rst',
2019
'master_doc': 'index',

sphinx_automodapi/tests/test_autodoc_enhancements.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import sys
2-
31
from textwrap import dedent
42

53
import pytest
@@ -15,23 +13,11 @@ def foo(cls):
1513
return 'foo'
1614

1715

18-
if sys.version_info[0] < 3:
19-
exec(dedent("""
20-
class MyClass(object):
21-
__metaclass__ = Meta
22-
@property
23-
def foo(self):
24-
\"\"\"Docstring for MyClass.foo property.\"\"\"
25-
return 'myfoo'
26-
"""))
27-
else:
28-
exec(dedent("""
29-
class MyClass(metaclass=Meta):
30-
@property
31-
def foo(self):
32-
\"\"\"Docstring for MyClass.foo property.\"\"\"
33-
return 'myfoo'
34-
"""))
16+
class MyClass(metaclass=Meta):
17+
@property
18+
def foo(self):
19+
"""Docstring for MyClass.foo property."""
20+
return 'myfoo'
3521

3622

3723
def test_type_attrgetter():

sphinx_automodapi/tests/test_automodapi.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Licensed under a 3-clause BSD style license - see LICENSE.rst
33

4-
import sys
54
from copy import copy
65

76
import pytest
@@ -10,11 +9,6 @@
109
from . import cython_testpackage # noqa
1110
from .helpers import run_sphinx_in_tmpdir
1211

13-
if sys.version_info[0] == 2:
14-
from io import open as io_open
15-
else:
16-
io_open = open
17-
1812

1913
def setup_function(func):
2014
# This can be replaced with the docutils_namespace context manager once
@@ -104,7 +98,7 @@ def test_am_replacer_writereprocessed(tmpdir, writereprocessed):
10498
Tests the automodapi_writereprocessed option
10599
"""
106100

107-
with io_open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f:
101+
with open(tmpdir.join('index.rst').strpath, 'w', encoding='utf-8') as f:
108102
f.write(am_replacer_repr_str.format(options=''))
109103

110104
run_sphinx_in_tmpdir(tmpdir, additional_conf={'automodapi_writereprocessed': writereprocessed})

sphinx_automodapi/tests/test_cases.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
# We store different cases in the cases sub-directory of the tests directory
55

66
import os
7-
import io
8-
import sys
97
import glob
108
import shutil
119
from itertools import product
@@ -26,8 +24,8 @@
2624

2725

2826
intersphinx_mapping = {
29-
'python': ('https://docs.python.org/{0}/'.format(sys.version_info[0]), None)
30-
}
27+
'python': ('https://docs.python.org/3/', None)
28+
}
3129

3230
DEFAULT_CONF = {'source_suffix': '.rst',
3331
'master_doc': 'index',
@@ -112,8 +110,8 @@ def test_run_full_case(tmpdir, case_dir, parallel):
112110
path_relative = os.path.relpath(path_reference, output_dir)
113111
path_actual = os.path.join(docs_dir, path_relative)
114112
assert os.path.exists(path_actual)
115-
with io.open(path_actual, encoding='utf8') as f:
113+
with open(path_actual, encoding='utf8') as f:
116114
actual = f.read()
117-
with io.open(path_reference, encoding='utf8') as f:
115+
with open(path_reference, encoding='utf8') as f:
118116
reference = f.read()
119117
assert actual.strip() == reference.strip()

sphinx_automodapi/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
__all__ = ['cleanup_whitespace',
1010
'find_mod_objs', 'find_autosummary_in_lines_for_automodsumm']
1111

12-
if sys.version_info[0] >= 3:
13-
def iteritems(dictionary):
14-
return dictionary.items()
15-
else:
16-
def iteritems(dictionary):
17-
return dictionary.iteritems()
18-
1912
# We use \n instead of os.linesep because even on Windows, the generated files
2013
# use \n as the newline character.
2114
SPACE_NEWLINE = ' \n'

0 commit comments

Comments
 (0)