Menu

#227 Python parser incorrectly detects function as methods

open-accepted
None
5
2008-06-11
2008-06-08
No

In the attached test case, the python parser detects "im_a_function" as a method of testClass but it is a function.
This happens because "im_a_function" starts on the same indentation level as the last parsed class before.

func_vs_method.patch tries to solve this by clearing the last parent string for the indentation level of the parsed line.
But this is more or less only a quick hack, I guess there is a better, proper solution.

Discussion

  • Enrico Tröger

    Enrico Tröger - 2008-06-08

    Test case

     
  • Enrico Tröger

    Enrico Tröger - 2008-06-08

    Quick hack

     
  • Enrico Tröger

    Enrico Tröger - 2008-06-08

    Logged In: YES
    user_id=1117045
    Originator: YES

    File Added: func_vs_method.patch

     
  • Elias Pschernig

    Elias Pschernig - 2008-06-11

    Logged In: YES
    user_id=32894
    Originator: NO

    Thanks, committed as of revision 667. The patch looked fine to me. So far, the only time the indentation level was checked was on encountering "def" or "class". Obviously, a check was needed also for the case when something else would have a smaller indentation, thus ending the block. Which is what you implemented.

     
  • Elias Pschernig

    Elias Pschernig - 2008-06-11
    • assigned_to: nobody --> elias
    • status: open --> open-accepted
     

Log in to post a comment.