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

Transform constants to variables with Final type hint #178

Open
ilnarkhasanov opened this issue Feb 28, 2024 · 5 comments
Open

Transform constants to variables with Final type hint #178

ilnarkhasanov opened this issue Feb 28, 2024 · 5 comments

Comments

@ilnarkhasanov
Copy link
Contributor

ilnarkhasanov commented Feb 28, 2024

According to PEP-0008, constants are usually declared at a module level.

In ast.py, (lines 366-368) we have 2 constants declared in if

if __name__ == '__main__':
    JAVA = sys.argv[1]
    METRICS = sys.argv[2]

The idea behind it is clear: JAVA and METRICS must not be changed.

What we can do is using Final type hint. It states that variable or attribute should not be reassigned, redefined, or overridden.

Suggestion:

if __name__ == '__main__':
    java: Final[str] = sys.argv[1]
    metrics: Final[str] = sys.argv[2]
@ilnarkhasanov
Copy link
Contributor Author

@yegor256 can you approve this as an issue, please?

@ilnarkhasanov
Copy link
Contributor Author

@yegor256 can you check it, please?

@yegor256
Copy link
Owner

yegor256 commented Mar 6, 2024

@ilnarkhasanov sounds like a reasonable suggestion, but let's first find out why Pylint doesn't complain about this:

According to PEP-0008, constants are usually declared at a module level.

Maybe we should use some other linter on top of pylint?

@howcanunot
Copy link
Contributor

Looks like pep doesn't force us to declare constants in top level. but you can extend your pylint with your own plugins using load-plugins= option (https://pylint.pycqa.org/en/latest/development_guide/how_tos/plugins.html)
I would suggest putting this in a directory and adding new plugins to it in the future.
I could try to write this :)
@yegor256 what do you thunk?

@yegor256
Copy link
Owner

@howcanunot please, try!)

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

3 participants