Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Incorrect behaviour for nested functions #14

Closed
JensRantil opened this issue Aug 9, 2012 · 2 comments
Closed

Incorrect behaviour for nested functions #14

JensRantil opened this issue Aug 9, 2012 · 2 comments
Labels

Comments

@JensRantil
Copy link
Contributor

If I check

def a():
    """Do something."""
    def b():
        """My other help function that's used in a()."""
        return 42

I will get the warning

test.py:2:4: PEP257 Return value type should be mentioned.

even though a() does not return anything.

@keleshev
Copy link
Contributor

here is the code for the check:

def check_return_type(def_docstring, context, is_script):
    """PEP257 Return value type should be mentioned.

    However, the nature of the return value cannot be determined by
    introspection, so it should be mentioned.

    """
    if (not def_docstring) or is_script:
        return
    if 'return' not in def_docstring.lower():
        tokens = list(tk.generate_tokens(StringIO(context).readline))
        after_return = [tokens[i + 1][0] for i, token in enumerate(tokens)
                        if token[1] == 'return']
        # not very precise (tk.OP ';' is not taken into account)
        if set(after_return) - set([tk.COMMENT, tk.NL, tk.NEWLINE]) != set([]):
            return "PEP257 Return value type should be mentioned.",

As you can see it checks if there is a 'return' token in the body of function. In order to solve this bug the function should skip nested functions...

I will try to fix this when I have time, otherwise you're welcome to submit a patch.

@Nurdok
Copy link
Member

Nurdok commented Sep 12, 2015

This check is currently skipped, so I'm closing the issue for now.

@Nurdok Nurdok closed this as completed Sep 12, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants