Skip to content
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

Document purpose for all assertion methods #2

Open
csparpa opened this issue Feb 10, 2019 · 6 comments
Open

Document purpose for all assertion methods #2

csparpa opened this issue Feb 10, 2019 · 6 comments

Comments

@csparpa
Copy link
Owner

csparpa commented Feb 10, 2019

Each assertion method should clearly document its purpose.

As the return values for each assertion method can either be the Check object instance itself or an exception and each method takes no parameter, docs are straightforward to write.

This is the first step towards having an automated documentation system - eg. see Sphinx setup on my other projects PyOWM or Baroque.

Example

Instead of:

def is_not_complex(self):
    try:
        assert not isinstance(self._val, complex)
        return self
    except AssertionError:
        raise CheckError('{} is complex'.format(self._val))

it would be nice to have

def is_not_complex(self):
    """
    Checks that the argument is not a complex number

    :returns: the self `fluentcheck.Check` instance if assertion succeeds
    :raises: `fluentcheck.CheckError` if assertion fails

    """
    try:
        assert not isinstance(self._val, complex)
        return self
    except AssertionError:
        raise CheckError('{} is complex'.format(self._val))
@hedyhli
Copy link
Contributor

hedyhli commented Jun 29, 2020

Interesting, in that case I guess those assertion methods doc string going to be really similar (because of the raises and return)

@hedyhli
Copy link
Contributor

hedyhli commented Jun 30, 2020

Looking into this... I think the tests should also have docstr

@deanagan
Copy link
Collaborator

Thanks Hedy. The tests can have them too. I wonder if existing documentation tools can automate the docstring generation.

@hedyhli
Copy link
Contributor

hedyhli commented Jun 30, 2020

Not that I know of, but maybe a small script can do it (to automate inserting :raises:, and :return: lines), and by the way interrogate can help to look for missing doc strings

@csparpa
Copy link
Owner Author

csparpa commented Jun 30, 2020

@hedythedev @deanagan this might help: https://stackoverflow.com/questions/37549741/is-it-possible-to-bulk-add-docstrings-to-all-the-functions-in-pycharm

@hedyhli
Copy link
Contributor

hedyhli commented Jul 2, 2020

I don’t use PyCharm, but vim-pydocstring should bulk add them for me 😄

csparpa pushed a commit that referenced this issue Feb 17, 2021
Use literal syntax instead of function calls to create data structure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants