-
-
Notifications
You must be signed in to change notification settings - Fork 555
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
Multi-line comments in Python are counted as code #100
Comments
Hello, thanks for filing the issue. I don't why they would be comments as they are str's. |
@Aaronepower ah, thanks, that makes sense. I'm used to thinking of those strings early in a function as comments but yes they're indeed multi-line strings and not multi-line comments as part of the language. To keep it generic, It may be that this approach also occurs in other programming languages but I'm not aware of any. Feel free to close this issue as this clarifies why tokei counts the lines the way it does. |
I think @svisser is on the right track here and I don't think Tokei should count strings like this as Python code. If the first statement in a Python module, class, method, or function is a string literal, it's considered a docstring and the statement becomes a special attribute on the class/method/whatever:
Although technically docstrings are code I wouldn't expect them to be counted as such — they're really Python's version of Rust's doc comments. |
@flother Technically correct is the best kind of correct 😛. I might consider adding a compile or runtime flag that would change the behavior with the default being the current. Since it is a common practice. |
Thanks for reconsidering this. Just to needlessly ram home my point: take a peek at It's a shame it would be a breaking change, because I'd love to see Tokei take these into account by default. I suppose that suggests I'd be in favour of a compile flag instead of a runtime flag, but I think I'd be more comfortable on the fence on that one. |
For the following file
example.py
:Tokei 5 reports the following:
whereas cloc 1.72 reports 4 comment, 2 code, 1 blank which I believe is correct as Python supports multi-line comments with
"""
and'''
.I tried to fix this by moving those comment characters in
languages.json
to"multi"
and by testing it again usingcargo build
and./target/debug/tokei example.py
but that didn't make a difference.Is this possibly due to the way it detects multi-line comments? I did notice that Python would be the first language in languages.json to use escaping when expressing multi-line comment strings but I don't know if that's related.
The text was updated successfully, but these errors were encountered: