hippogriffe 0.1.0__tar.gz → 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hippogriffe
3
- Version: 0.1.0
3
+ Version: 0.1.1
4
4
  Summary: A simple ipynb->md converter for MkDocs
5
5
  Project-URL: repository, https://github.com/patrick-kidger/hippogriffe
6
6
  Author-email: Patrick Kidger <contact@kidger.site>
@@ -229,6 +229,8 @@ This is a set of tweaks on top of the MkDocs + `mkdocstrings[python]` + `griffe`
229
229
  - Fixes unions/generics/etc. to display as e.g. `int | str` rather than just `Union`, or `tuple[int, str]` rather than just `tuple`.
230
230
  - Respects your public API: if a type is declared in your documentation as `::: yourlib.Foo` then its usage in type annotations will match: `some_fn(foo: yourlib.Foo)`.
231
231
  - Show base classes inline after the class.
232
+ - Drops the `-> None` return annotation from `__init__` methods.
233
+ - Attributes display as `[attr] somelib.someattr` instead of `[attr] somelib.someattr = some_value [module]`. (I don't find usually-long default values to be useful documentation, nor the 'module' tag to be informative.)
232
234
 
233
235
  Before | After
234
236
  :---------------------:|:----------------------:
@@ -7,6 +7,8 @@ This is a set of tweaks on top of the MkDocs + `mkdocstrings[python]` + `griffe`
7
7
  - Fixes unions/generics/etc. to display as e.g. `int | str` rather than just `Union`, or `tuple[int, str]` rather than just `tuple`.
8
8
  - Respects your public API: if a type is declared in your documentation as `::: yourlib.Foo` then its usage in type annotations will match: `some_fn(foo: yourlib.Foo)`.
9
9
  - Show base classes inline after the class.
10
+ - Drops the `-> None` return annotation from `__init__` methods.
11
+ - Attributes display as `[attr] somelib.someattr` instead of `[attr] somelib.someattr = some_value [module]`. (I don't find usually-long default values to be useful documentation, nor the 'module' tag to be informative.)
10
12
 
11
13
  Before | After
12
14
  :---------------------:|:----------------------:
@@ -23,6 +23,10 @@ def get_templates_path():
23
23
  return _here / "templates"
24
24
 
25
25
 
26
+ class _NotInPublicApiException(Exception):
27
+ pass
28
+
29
+
26
30
  class _PublicApi:
27
31
  def __init__(
28
32
  self,
@@ -100,7 +104,8 @@ class _PublicApi:
100
104
  for m in self._public_modules:
101
105
  if key.startswith(m + "."):
102
106
  return key, False
103
- raise Exception(
107
+ # Not using `KeyError` because that displays its message with `repr`.
108
+ raise _NotInPublicApiException(
104
109
  f"Tried and failed to find {key} in the public API. Commons reasons "
105
110
  "for this error are:\n"
106
111
  "- If it is from outside this package, then that package is not listed "
@@ -216,7 +221,7 @@ def _collect_bases(
216
221
  elif isinstance(base, griffe.Class):
217
222
  try:
218
223
  base, autoref = public_api[base.path]
219
- except KeyError:
224
+ except _NotInPublicApiException:
220
225
  bases.update(_collect_bases(base, public_api, public_modules))
221
226
  else:
222
227
  bases[base] = autoref
@@ -283,7 +288,31 @@ class HippogriffeExtension(griffe.Extension):
283
288
  ) -> None:
284
289
  del agent, kwargs
285
290
  assert not isinstance(node, ast.AST)
286
- func.extra["hippogriffe"]["signature"] = inspect.signature(node.obj)
291
+ signature = inspect.signature(node.obj)
292
+ try:
293
+ name = node.obj.__name__
294
+ except AttributeError:
295
+ pass
296
+ else:
297
+ if name == "__init__":
298
+ signature = signature.replace(return_annotation=inspect.Signature.empty)
299
+ func.extra["hippogriffe"]["signature"] = signature
300
+
301
+ def on_attribute_instance(
302
+ self,
303
+ *,
304
+ node: ast.AST | griffe.ObjectNode,
305
+ attr: griffe.Attribute,
306
+ agent: griffe.Visitor | griffe.Inspector,
307
+ **kwargs: Any,
308
+ ) -> None:
309
+ del node, agent, kwargs
310
+ # Knowing the value is IMO usually not useful. That is what documentation
311
+ # directly is for.
312
+ attr.value = None
313
+ # This is used to indicate that it is a module attribute, but IMO that's not
314
+ # super clear in the docs.
315
+ attr.labels.discard("module")
287
316
 
288
317
  def on_package_loaded(
289
318
  self, *, pkg: griffe.Module, loader: griffe.GriffeLoader, **kwargs: Any
@@ -12,6 +12,10 @@ from mkdocstrings import AutoDocProcessor
12
12
 
13
13
 
14
14
  _here = pathlib.Path(__file__).resolve().parent
15
+ _regex = re.compile(
16
+ r"^\s*" + AutoDocProcessor.regex.pattern.removeprefix("^"),
17
+ AutoDocProcessor.regex.flags,
18
+ )
15
19
 
16
20
 
17
21
  class PluginConfig(Config):
@@ -102,7 +106,7 @@ class HippogriffePlugin(BasePlugin[PluginConfig]):
102
106
  top_level_public_api.remove("")
103
107
  for file in files:
104
108
  if file.is_documentation_page():
105
- for match in AutoDocProcessor.regex.finditer(file.content_string):
109
+ for match in _regex.finditer(file.content_string):
106
110
  top_level_public_api.add(match["name"])
107
111
  files.append(
108
112
  File.generated(
@@ -25,7 +25,7 @@ name = "hippogriffe"
25
25
  readme = "README.md"
26
26
  requires-python = ">=3.10"
27
27
  urls = {repository = "https://github.com/patrick-kidger/hippogriffe"}
28
- version = "0.1.0"
28
+ version = "0.1.1"
29
29
 
30
30
  [project.optional-dependencies]
31
31
  dev = ["pre-commit"]
File without changes
File without changes