securedrop-client
securedrop-client copied to clipboard
Update __init__ args to show actual type signature
For example, it would be nice if help(Reply)
actually showed me the arguments I need to init an object.
Currently:
>>> help(Reply)
Help on class Reply in module sdclientapi.sdlocalobjects:
class Reply(builtins.object)
| This class represents a reply to the source.
|
| Methods defined here:
|
| __init__(self, **kwargs) -> None
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
Also help(type(Reply))
to does not provide additional help.
One possible resolution for defining tedious __init__
, __eq__
, and other dunder methods would be to offload that to attrs
.
Note, this is heavily related to freedomofpress/securedrop-sdk#31 and freedomofpress/securedrop-sdk#32.
@nabla-c0d3 Any thoughts on this approach / are you potentially interested in helping with it?
@eloquence Sure - I could look into it.
What versions of Python is securedrop-sdk targeting? I can think of two really good approaches for this kind of problem:
- pydantic, which is Python 3.6+
- dataclasses which are Python 3.7+
@eloquence I made a poc PR for 1) at https://github.com/freedomofpress/securedrop-sdk/pull/149
For this particular usecase, we just have to add correct docstrings explaining the arguments and their type information. That would be a simple but totally useful solution. Right now, __init__
does not have any doctstring, and if we add some, it shows up properly via the help()
call.