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

N806 Constant inside function false positive #86

Closed
fallenflint opened this issue Dec 6, 2018 · 2 comments
Closed

N806 Constant inside function false positive #86

fallenflint opened this issue Dec 6, 2018 · 2 comments

Comments

@fallenflint
Copy link

fallenflint commented Dec 6, 2018


According to test, "constants" inside functions are forbidden.
But there is no evidence of such rule in PEP8, except the statement

constants are usually defined on a module level

Which is definetely don't forbid function-level constant. It could be if it was said always
I've been arguing the topic with my teammate, and never found any direct prohibition for function-level constants. Finally, he sent me a link to this test.

I'd be very glad if you proof me wrong by pointing to direct or implicit prohibition of constants usage inside of functions/methods in PEP. Or proof me right and update test (though I currently have no idea how to separate simple variable assignemnt from "constant" definition.

Just for example, one of the cases is:

class TestCase:
     URL_1 = <some_value>
     URL_2 = <some_value>
     def test_1:
          ... URL_1 usage
     def test_2:
          ... URL_2 usage

versus

class TestCase:
    def test_1:
        URL = <some_value_for_1st_test>
        ... URL usage (may be multiple times)
    def test_2:
        URL = <some_value_for_2nd_test>
        ... URL usage (may be multiple times)

I'm pretty sure that the given case is PEP-compliant and semantycally correct - it's absolutely essential to treat some values as constant inside test case and emphasize it's immutability. For example if I define dataset to make checks against it.

@sigmavirus24
Copy link
Member

We're not here to help people win debates

@fallenflint
Copy link
Author

fallenflint commented Dec 7, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants