yegor256 / cam

Classes and Metriсs (CaM): a dataset of Java classes from public open-source GitHub repositories
http://cam.yegor256.com
MIT License
23 stars 35 forks source link

Transform constants to variables with `Final` type hint #178

Open ilnarkhasanov opened 7 months ago

ilnarkhasanov commented 7 months ago

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 commented 7 months ago

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

ilnarkhasanov commented 6 months ago

@yegor256 can you check it, please?

yegor256 commented 6 months ago

@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 commented 6 months ago

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 commented 6 months ago

@howcanunot please, try!)