Giter Site home page Giter Site logo

Incorrect lloc count about radon HOT 2 OPEN

shabi9605 avatar shabi9605 commented on June 11, 2024
Incorrect lloc count

from radon.

Comments (2)

devdanzin avatar devdanzin commented on June 11, 2024

Confirmed, and you have identified the right reason.

A simple (but not perfect) fix would be to, besides checking for a colon, also check for a compound statement keyword on the line. That would fix the provided example.

So instead of:

return 2 - (token_pos == len(processed) - 2)

We'd have something like(untested):

            # Only consider colons when a compound statement is found in the line
            if any(token.string in COMPOUND_KEYWORDS for token in processed): 
                return 2 - (token_pos == len(processed) - 2)
            return 1

Where COMPOUND_KEYWORDS is:

COMPOUND_KEYWORDS = {"if", "while", "for", "try", "with", "match", "def", "class", "else", "elif", "except", "finally", "case"}

That still leaves at least one issue: both match and case are soft keywords, so we might get wrong lloc counts for something like:

case = {1: 2}
match = {3: 4}

It seems that a line with a soft keyword match always ends with a colon, so it would be possible to check for that. But a line with a case can have further statements, so it might be trickier to get right.

Edited to add: It would also be necessary to decide on how to treat lambda: currently it counts as two logical lines because it has a colon. Should it? And if it's two logical lines, how do we count the following:

def a(b=lambda x: 1):
    pass

from radon.

devdanzin avatar devdanzin commented on June 11, 2024

I've added a PR to fix this, #263. It doesn't consider lambda x: y as two logical lines, as it would make a mess of counting lambda x: lambda y: lambda z: 1.

from radon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.