Skip to content

Commit ff6da6a

Browse files
function-valued default parameters are now represented as jut <function foo>
1 parent ee0cc2d commit ff6da6a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
repos:
22
- repo: https://github.com/ambv/black
3-
rev: stable
3+
rev: 22.3.0
44
hooks:
55
- id: black
66
- repo: https://github.com/PyCQA/isort
7-
rev: 5.9.3
7+
rev: 5.10.1
88
hooks:
99
- id: isort
1010
- repo: https://github.com/pycqa/flake8
11-
rev: 3.9.2
11+
rev: 4.0.1
1212
hooks:
1313
- id: flake8

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ _For use as part of the documentation-generation-for-Python stack that comprises
1212
- Adds an `abstractmethod`/`abstractproperty` property to appear in the documentation instead. (Useful when specifying abstract base classes.)
1313
- Removed the `dataclass` and `special` properties that appear in the documentation. (I find that these just add visual noise.)
1414
- Removed the `-> None` return annotation on `__init__` methods.
15+
- Function-valued defaults now display as just `<function foo>` rather than `<function foo at 0x7f5428d27a60>`.
1516

1617
Note that you must run the `mkdocs` command twice, as these custom tweaks write a cache to disk -- listing all the public objects -- that are then used on the second run. If you see a `.all_objects.cache` file appear -- this is why. (You may wish to add the file to your `.gitignore`.)
1718

pytkdocs_tweaks/__init__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
import pytkdocs
1313
import pytkdocs.cli
14+
import pytkdocs.serializer
1415

1516

16-
__version__ = "0.0.4"
17+
__version__ = "0.0.5"
1718

1819

1920
_cachefile = pathlib.Path(".all_objects.cache")
@@ -230,8 +231,20 @@ def process_config(config):
230231
if not _cachefile.exists():
231232
with _cachefile.open("w") as f:
232233
json.dump({}, f)
234+
233235
pytkdocs.cli.process_config = process_config
234236

237+
_serialize_signature_parameter = pytkdocs.serializer.serialize_signature_parameter
238+
239+
def serialize_signature_parameter(parameter):
240+
out = _serialize_signature_parameter(parameter)
241+
if inspect.isfunction(parameter.default):
242+
assert "default" in out
243+
out["default"] = f"<function {parameter.default.__name__}>"
244+
return out
245+
246+
pytkdocs.serializer.serialize_signature_parameter = serialize_signature_parameter
247+
235248
# By default pytkdocs has some really weird behaviour in which the docstring for
236249
# inherited magic methods are removed. This removes that behaviour.
237250
pytkdocs.loader.RE_SPECIAL = argparse.Namespace(match=lambda _: False)

0 commit comments

Comments
 (0)