summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/__init__.py2
-rw-r--r--sphinx/util/i18n.py2
-rw-r--r--sphinx/util/images.py2
-rw-r--r--sphinx/util/inspect.py19
-rw-r--r--sphinx/util/osutil.py9
5 files changed, 14 insertions, 20 deletions
diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py
index 8ea5641c9..90e0e6a18 100644
--- a/sphinx/util/__init__.py
+++ b/sphinx/util/__init__.py
@@ -208,7 +208,7 @@ def copy_static_entry(source, targetdir, builder, context={},
Handles all possible cases of files, directories and subdirectories.
"""
warnings.warn('sphinx.util.copy_static_entry is deprecated for removal',
- RemovedInSphinx30Warning)
+ RemovedInSphinx30Warning, stacklevel=2)
if exclude_matchers:
relpath = relative_path(path.join(builder.srcdir, 'dummy'), source)
diff --git a/sphinx/util/i18n.py b/sphinx/util/i18n.py
index 4e25115a7..eca5a8cf8 100644
--- a/sphinx/util/i18n.py
+++ b/sphinx/util/i18n.py
@@ -123,7 +123,7 @@ def find_catalog_source_files(locale_dirs, locale, domains=None, gettext_compact
"""
if gettext_compact is not None:
warnings.warn('gettext_compact argument for find_catalog_source_files() '
- 'is deprecated.', RemovedInSphinx30Warning)
+ 'is deprecated.', RemovedInSphinx30Warning, stacklevel=2)
catalogs = set() # type: Set[CatalogInfo]
diff --git a/sphinx/util/images.py b/sphinx/util/images.py
index 85fbf17f1..d7e5de787 100644
--- a/sphinx/util/images.py
+++ b/sphinx/util/images.py
@@ -85,7 +85,7 @@ def guess_mimetype(filename='', content=None, default=None):
return mime_suffixes[ext]
elif content:
warnings.warn('The content argument of guess_mimetype() is deprecated.',
- RemovedInSphinx30Warning)
+ RemovedInSphinx30Warning, stacklevel=2)
return guess_mimetype_for_stream(BytesIO(content), default=default)
elif path.exists(filename):
with open(filename, 'rb') as f:
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 541d5f5c5..82814e00d 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -322,19 +322,12 @@ class Signature:
raise
try:
- if ispartial(subject):
- # get_type_hints() does not support partial objects
- self.annotations = {} # type: Dict[str, Any]
- else:
- self.annotations = typing.get_type_hints(subject) # type: ignore
- except Exception as exc:
- if (3, 5, 0) <= sys.version_info < (3, 5, 3) and isinstance(exc, AttributeError):
- # python 3.5.2 raises ValueError for classmethod-ized partial objects.
- self.annotations = {}
- else:
- logger.warning('Invalid type annotation found on %r. Ignored: %r',
- subject, exc)
- self.annotations = {}
+ self.annotations = typing.get_type_hints(subject) # type: ignore
+ except Exception:
+ # get_type_hints() does not support some kind of objects like partial,
+ # ForwardRef and so on. For them, it raises an exception. In that case,
+ # we try to build annotations from argspec.
+ self.annotations = {}
if bound_method:
# client gives a hint that the subject is a bound method
diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py
index 11b082e7d..c7c0b0690 100644
--- a/sphinx/util/osutil.py
+++ b/sphinx/util/osutil.py
@@ -84,9 +84,10 @@ def ensuredir(path):
"""Ensure that a path exists."""
try:
os.makedirs(path)
- except OSError as err:
- # 0 for Jython/Win32
- if err.errno not in [0, EEXIST]:
+ except OSError:
+ # If the path is already an existing directory (not a file!),
+ # that is OK.
+ if not os.path.isdir(path):
raise
@@ -155,7 +156,7 @@ def ustrftime(format, *args):
# type: (unicode, Any) -> unicode
"""[DEPRECATED] strftime for unicode strings."""
warnings.warn('sphinx.util.osutil.ustrtime is deprecated for removal',
- RemovedInSphinx30Warning)
+ RemovedInSphinx30Warning, stacklevel=2)
if not args:
# If time is not specified, try to use $SOURCE_DATE_EPOCH variable