Skip to content

Add ignore__init option #136

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

Merged
merged 1 commit into from
Aug 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ excptions add to docstring.
"""
raise Exception('foo')

Ignore generate __init__ docstring
----------------------------------

If you want ignore to generate `__init__` docstring, you can set like following.

.. code::

let g:pydocstring_ignore_init = 1

Thanks
------

Expand Down
3 changes: 3 additions & 0 deletions autoload/pydocstring.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let g:pydocstring_doq_path = get(
\ 'pydocstring_doq_path',
\ printf('%s/lib/doq', expand('<sfile>:p:h:h'))
\ )
let g:pydocstring_ignore_init = get(g:, 'pydocstring_ignore_init', 0)

let s:results = []

Expand Down Expand Up @@ -180,6 +181,8 @@ endfunction
function! pydocstring#format() abort
let lines = printf("%s\n", join(getbufline(bufnr('%'), 1, '$'), "\n"))
let cmd = s:create_cmd('string', '')
let cmd = g:pydocstring_ignore_init ? printf('%s --ignore_init', cmd) : cmd

let indent = s:get_indent_width()
let end_lineno = line('.')
call s:execute(
Expand Down
5 changes: 5 additions & 0 deletions doc/pydocstring.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,10 @@ g:pydocstring_enable_mapping *g:pydocstring_enable_mapping*

Default value is '1'

g:pydocstring_ignore_init *g:pydocstring_ignore_init*
Ignore to generate __init__ method docstring.
This option only available at `:PydocstringFormat`
Default value is '0'

==============================================================================
vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0:
39 changes: 39 additions & 0 deletions tests/format.vader
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,42 @@ Expect python:
:param arg2:
"""
pass

Given python (Ignore __init__):
class Foo:
def __init__(self, arg1):
pass

def foo(arg1):
pass

def bar(arg1, arg2):
pass


Execute:
:let g:pydocstring_ignore_init = 1
:PydocstringFormat
:sleep 1

Expect python:
class Foo:
"""Foo."""

def __init__(self, arg1):
pass

def foo(arg1):
"""foo.

:param arg1:
"""
pass

def bar(arg1, arg2):
"""bar.

:param arg1:
:param arg2:
"""
pass