Skip to content

Commit

Permalink
dep: Add cached-property package (for py37 or older)
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Jan 4, 2020
1 parent f83349d commit 1d027d2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -4,6 +4,7 @@ Release 3.0.0 (in development)
Dependencies
------------

* Add ``cached-property`` package (for py37 or older)
* LaTeX: drop dependency on :program:`extractbb` for image inclusion in
Japanese documents as ``.xbb`` files are unneeded by :program:`dvipdfmx`
since TeXLive2015 (refs: #6189)
Expand Down
4 changes: 4 additions & 0 deletions setup.py
Expand Up @@ -31,13 +31,17 @@
'requests>=2.5.0',
'setuptools',
'packaging',
'cached-property',
]

extras_require = {
# Environment Marker works for wheel 0.24 or later
':sys_platform=="win32"': [
'colorama>=0.3.5',
],
':python_version<"3.8"': [
'cached-property',
],
'docs': [
'sphinxcontrib-websupport',
],
Expand Down
10 changes: 8 additions & 2 deletions sphinx/pycode/function.py
Expand Up @@ -9,11 +9,17 @@
"""

import ast
import sys
from collections import OrderedDict
from inspect import Parameter
from typing import cast
from typing import Mapping

if sys.version_info > (3, 8):
from functools import cached_property
else:
from cached_property import cached_property


def stringify(node: ast.AST) -> str:
"""Stringify an AST node."""
Expand Down Expand Up @@ -74,7 +80,7 @@ def __init__(self, signature: str) -> None:
module = ast.parse('def func' + signature + ': pass')
self.definition = cast(ast.FunctionDef, module.body[0])

@property
@cached_property
def parameters(self) -> Mapping:
args = self.definition.args
params = []
Expand Down Expand Up @@ -113,6 +119,6 @@ def parameters(self) -> Mapping:

return OrderedDict((p.name, p) for p in params)

@property
@cached_property
def return_annotation(self) -> str:
return stringify(self.definition.returns)

0 comments on commit 1d027d2

Please sign in to comment.