You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the "optional" statement isn't used in any way right now,
enforcing a specific layout for what comes after the "doctype" serves
no useful purpose. I don't intend docstub to be linter so I don't think
it's likely that we will ever enforce annotating that a parameter is
"optional" in the docstring – while it's nice to do so, it's reasonably
easy to see it from the signature.
Update the docs accordingly. Also try to be more precise about
differentiating "doctypes" from valid Python types.
Copy file name to clipboardExpand all lines: docs/typing_syntax.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,24 +7,24 @@
7
7
> Several features are experimental and included to make adoption of docstub easier.
8
8
> Long-term, some of these might be discouraged or removed as docstub matures.
9
9
10
-
Docstub defines its own [grammar](../src/docstub/doctype.lark) to parse and transform type information in docstrings into valid type annotations.
10
+
Docstub defines its own [grammar](../src/docstub/doctype.lark) to parse and transform type information in docstrings (doctypes) into valid Python type expressions.
11
11
This grammar fully supports [Python's conventional typing syntax](https://typing.python.org/en/latest/index.html).
12
-
So any type annotation that is valid in Python, can be used in a docstrings as is.
12
+
So any type expression that is valid in Python, can be used in a docstrings as is.
13
13
In addition, docstub extends this syntax with several "natural language" expressions that are commonly used in the scientific Python ecosystem.
14
14
15
-
Docstrings are expected to follow the NumPyDoc style:
15
+
Docstrings should follow a form that is inspired by the NumPyDoc style:
16
16
```
17
17
Section name
18
18
------------
19
-
name : annotation, optional, extra_info
19
+
name : doctype, extra_info
20
20
Description.
21
21
```
22
22
23
-
-`name` might be the name of a parameteror attribute.
24
-
Other sections like "Returns" or "Yields" are supported.
25
-
-`annotation` the actual type information that will be transformed into the type annotation.
26
-
-`optional` and `extra_info` can be appended to provide additional information.
27
-
Their presence and content doesn't currently affect the resulting type annotation.
23
+
-`name` might be the name of a parameter, attribute or similar.
24
+
-`doctype` the actual type information that will be transformed into a Python type.
25
+
-`extra_info` is optional and captures anything after the first comma (that is not inside a type expression).
26
+
It is useful to provide additional information for readers.
27
+
Its presence and content doesn't currently affect the resulting type annotation.
Copy file name to clipboardExpand all lines: docs/user_guide.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,21 +93,21 @@ def example_metric(
93
93
There are several interesting things to note here:
94
94
95
95
- Many existing conventions that the scientific Python ecosystem uses, will work out of the box.
96
-
In this case, docstub knew how to translate `array-like`, `array of dtype uint8` into a valid type annotation in the stub file.
97
-
In a similar manner, `or` can be used as a "natural language" alternative to `|`.
96
+
In this case, docstub knew how to translate `array-like`, `array of dtype uint8` into a valid Python type for the stub file.
97
+
In a similar manner, `or` can be used as a "natural language" alternative to `|` to form unions.
98
98
You can find more details in [Typing syntax in docstrings](typing_syntax.md).
99
99
100
-
- Optional arguments that default to `None` are recognized and a `| None` is appended automatically if the type doesn't include it already.
100
+
- Optional arguments that default to `None` are recognized and a `| None` is appended automatically.
101
101
The `optional` or `default = ...` part don't influence the annotation.
102
102
103
103
- Referencing the `float` and `Iterable` types worked out of the box.
104
-
All builtin types as well as types from the standard libraries `typing` and `collections.abc` module can be used.
104
+
All builtin types as well as types from the standard libraries `typing` and `collections.abc` module can be used like this.
105
105
Necessary imports will be added automatically to the stub file.
106
106
107
107
108
-
## Using types & nicknames
108
+
## Referencing types & nicknames
109
109
110
-
To translate a type from a docstring into a valid type annotation, docstub needs to know where that type originates from and how to import it.
110
+
To translate a type from a docstring into a valid type annotation, docstub needs to know where names inthat typeare defined from where to import them.
111
111
Out of the box, docstub will know about builtin types such as `int` or `bool` that don't need an import, and types in `typing`, `collections.abc` from Python's standard library.
112
112
It will source these from the Python environment it is installed in.
113
113
In addition to that, docstub will collect all types in the package directory you are running it on.
0 commit comments