-
Notifications
You must be signed in to change notification settings - Fork 62
Handling of attrs and dataclass constructors #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 70 commits
bf5716a
f7d0d1a
d87e745
f022cdf
d578d4c
6f8e806
24d5ad6
379c63e
a527d97
c5fc9b9
c4be1a9
a2389dc
36e3683
d974015
d1281cf
41d8ddb
bb7c62c
ba47bab
1f74226
9b3860b
a3f0cd3
4822ea9
3f8c7f6
31ef268
c06de7e
2155fec
4b9142e
cf8ba4e
f7220e9
def0ee0
5a1939c
411a584
5c72350
3720604
299cd58
7497b7a
6a33634
4ce9b97
4016b4c
eb83341
06e06e1
63edbed
1e82784
435ac99
bcce4f3
ad9bfef
607a89a
3e512f4
11ba98c
83adf80
ce1e05f
34d7bb3
fe08559
89a58ef
d4deb77
d81bf62
45a5d3a
4926d47
2ac31e7
b21ad7e
417e995
a1fff97
60c319e
b59a6c0
a62e2f2
bd658dc
da74a74
537ecf7
7ad8099
b79a7d7
88ff3ed
dcc5e07
049b417
6a3c870
c15fb73
faed763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -26,8 +26,7 @@ Pydoctor also supports *attribute docstrings*:: | |||||
| """This docstring describes a class variable.""" | ||||||
|
|
||||||
| def __init__(self): | ||||||
| self.ivar = [] | ||||||
| """This docstring describes an instance variable.""" | ||||||
| self.ivar = [];"It can also be used inline." | ||||||
|
|
||||||
| Attribute docstrings are not part of the Python language itself (`PEP 224 <https://www.python.org/dev/peps/pep-0224/>`_ was rejected), so these docstrings are not available at runtime. | ||||||
|
|
||||||
|
|
@@ -284,6 +283,45 @@ If you are using explicit ``attr.ib`` definitions instead of ``auto_attribs``, p | |||||
| list_of_numbers = attr.ib(factory=list) # type: List[int] | ||||||
| """Multiple numbers.""" | ||||||
|
|
||||||
| Pydoctor look for ``attrs`` fields declarations and analyze the | ||||||
| arguments passed to ``attr.s`` and ``attr.ib`` in order to | ||||||
| precisely infer what's the signature of the constructor method:: | ||||||
|
|
||||||
| from typing import List | ||||||
| import pathlib | ||||||
| import attr | ||||||
|
|
||||||
| def convert_paths(p:List[str]) -> List[pathlib.Path]: | ||||||
| return [pathlib.Path(s) for s in p] | ||||||
|
|
||||||
| @attr.s(auto_attribs=True) | ||||||
| class Base: | ||||||
| a: int | ||||||
|
|
||||||
| @attr.s(auto_attribs=True, kw_only=True) | ||||||
| class SomeClass(Base): | ||||||
| a_number:int=42; "docstring of number A." | ||||||
| list_of_numbers:List[int] = attr.ib(factory=list); "List of ints" | ||||||
| converted_paths:List[pathlib.Path] = attr.ib(converter=convert_paths, factory=list); "Uses a converter" | ||||||
|
|
||||||
| The constrcutor method will be documented as if it was explicitly defined, | ||||||
| with a docstring including documentation of each parameters and a note | ||||||
| saying the method is generated by attrs:: | ||||||
|
|
||||||
| def __init__(self, *, a: int, a_number: int = 42, | ||||||
| list_of_numbers: List[int] = list(), | ||||||
| converted_paths: List[str] = list()): | ||||||
| """ | ||||||
| attrs generated method | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be a note like |
||||||
|
|
||||||
| @param a_number: docstring of number A. | ||||||
| @param list_of_numbers: C{attr.ib(factory=list)} | ||||||
| List of ints | ||||||
| @param converted_paths: C{attr.ib(converter=convert_paths, factory=list)} | ||||||
| Uses a converter | ||||||
| """ | ||||||
|
|
||||||
| Pydoctor also supports the newer APIs (``attrs.define``/``attrs.field``). | ||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
|
||||||
| Private API | ||||||
| ----------- | ||||||
|
|
||||||
Uh oh!
There was an error while loading. Please reload this page.