diff options
| author | Dmitry Shachnev <mitya57@gmail.com> | 2014-01-19 14:17:10 +0400 |
|---|---|---|
| committer | Dmitry Shachnev <mitya57@gmail.com> | 2014-01-19 14:17:10 +0400 |
| commit | 344417db950d6e816ab2efb21737c2bdf9d1ad53 (patch) | |
| tree | 97b00b55be0e28a73399acc0f80e21e6a4e24b28 /sphinx/util | |
| parent | 59b355edaa4f17aff910bf2371526d5ce46fb648 (diff) | |
| download | sphinx-344417db950d6e816ab2efb21737c2bdf9d1ad53.tar.gz | |
Modernize the code now that Python 2.5 is no longer supported
- Use print function instead of print statement;
- Use new exception handling;
- Use in operator instead of has_key();
- Do not use tuple arguments in functions;
- Other miscellaneous improvements.
This is based on output of `futurize --stage1`, with some
manual corrections.
Diffstat (limited to 'sphinx/util')
| -rw-r--r-- | sphinx/util/__init__.py | 6 | ||||
| -rw-r--r-- | sphinx/util/docfields.py | 6 | ||||
| -rw-r--r-- | sphinx/util/docstrings.py | 4 | ||||
| -rw-r--r-- | sphinx/util/inspect.py | 6 | ||||
| -rw-r--r-- | sphinx/util/matching.py | 2 | ||||
| -rw-r--r-- | sphinx/util/osutil.py | 9 | ||||
| -rw-r--r-- | sphinx/util/pycompat.py | 2 |
7 files changed, 17 insertions, 18 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 5cbbb61b..7101a97d 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -209,7 +209,7 @@ def get_module_source(modname): if modname not in sys.modules: try: __import__(modname) - except Exception, err: + except Exception as err: raise PycodeError('error importing %r' % modname, err) mod = sys.modules[modname] filename = getattr(mod, '__file__', None) @@ -217,12 +217,12 @@ def get_module_source(modname): if loader and getattr(loader, 'get_filename', None): try: filename = loader.get_filename(modname) - except Exception, err: + except Exception as err: raise PycodeError('error getting filename for %r' % filename, err) if filename is None and loader: try: return 'string', loader.get_source(modname) - except Exception, err: + except Exception as err: raise PycodeError('error getting source for %r' % modname, err) if filename is None: raise PycodeError('no source found for module %r' % modname) diff --git a/sphinx/util/docfields.py b/sphinx/util/docfields.py index 150bf3a1..e42d5c49 100644 --- a/sphinx/util/docfields.py +++ b/sphinx/util/docfields.py @@ -240,10 +240,8 @@ class DocFieldTransformer(object): if is_typefield: # filter out only inline nodes; others will result in invalid # markup being written out - content = filter( - lambda n: isinstance(n, nodes.Inline) or - isinstance(n, nodes.Text), - content) + content = [n for n in content if isinstance(n, nodes.Inline) or + isinstance(n, nodes.Text)] if content: types.setdefault(typename, {})[fieldarg] = content continue diff --git a/sphinx/util/docstrings.py b/sphinx/util/docstrings.py index d45b938d..97303bd7 100644 --- a/sphinx/util/docstrings.py +++ b/sphinx/util/docstrings.py @@ -23,7 +23,7 @@ def prepare_docstring(s, ignore=1): """ lines = s.expandtabs().splitlines() # Find minimum indentation of any non-blank lines after ignored lines. - margin = sys.maxint + margin = sys.maxsize for line in lines[ignore:]: content = len(line.lstrip()) if content: @@ -33,7 +33,7 @@ def prepare_docstring(s, ignore=1): for i in range(ignore): if i < len(lines): lines[i] = lines[i].lstrip() - if margin < sys.maxint: + if margin < sys.maxsize: for i in range(ignore, len(lines)): lines[i] = lines[i][margin:] # Remove any leading blank lines. while lines and not lines[0]: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index c7556d05..d835bc41 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -60,7 +60,7 @@ else: # 2.6, 2.7 def getargspec(func): """Like inspect.getargspec but supports functools.partial as well.""" if inspect.ismethod(func): - func = func.im_func + func = func.__func__ parts = 0, () if type(func) is partial: keywords = func.keywords @@ -70,8 +70,8 @@ else: # 2.6, 2.7 func = func.func if not inspect.isfunction(func): raise TypeError('%r is not a Python function' % func) - args, varargs, varkw = inspect.getargs(func.func_code) - func_defaults = func.func_defaults + args, varargs, varkw = inspect.getargs(func.__code__) + func_defaults = func.__defaults__ if func_defaults is None: func_defaults = [] else: diff --git a/sphinx/util/matching.py b/sphinx/util/matching.py index b4c71076..61059c7c 100644 --- a/sphinx/util/matching.py +++ b/sphinx/util/matching.py @@ -77,4 +77,4 @@ def patfilter(names, pat): if pat not in _pat_cache: _pat_cache[pat] = re.compile(_translate_pattern(pat)) match = _pat_cache[pat].match - return filter(match, names) + return list(filter(match, names)) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index a5c461a6..a0b669f1 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -8,6 +8,7 @@ :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ +from __future__ import print_function import os import re @@ -63,7 +64,7 @@ def ensuredir(path): """Ensure that a path exists.""" try: os.makedirs(path) - except OSError, err: + except OSError as err: # 0 for Jython/Win32 if err.errno not in [0, EEXIST]: raise @@ -83,9 +84,9 @@ def walk(top, topdown=True, followlinks=False): try: fullpath = path.join(top, name) except UnicodeError: - print >>sys.stderr, ( - '%s:: ERROR: non-ASCII filename not supported on this ' - 'filesystem encoding %r, skipped.' % (name, fs_encoding)) + print('%s:: ERROR: non-ASCII filename not supported on this ' + 'filesystem encoding %r, skipped.' % (name, fs_encoding), + file=sys.stderr) continue if path.isdir(fullpath): dirs.append(name) diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 9941dc0c..4c9ef18d 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -41,7 +41,7 @@ if sys.version_info >= (3, 0): source = refactoring_tool._read_python_source(filepath)[0] try: tree = refactoring_tool.refactor_string(source, 'conf.py') - except ParseError, err: + except ParseError as err: # do not propagate lib2to3 exceptions lineno, offset = err.context[1] # try to match ParseError details with SyntaxError details |
