Skip to content

Blamed location is wrong when return type annotation is violated #15#29

Merged
skogsbaer merged 21 commits intomasterfrom
feature/15-locate-return
Sep 30, 2021
Merged

Blamed location is wrong when return type annotation is violated #15#29
skogsbaer merged 21 commits intomasterfrom
feature/15-locate-return

Conversation

@CodeSteak
Copy link
Collaborator

closes #15

Extra function calls are inserted in the AST. If a "return"-location is searched, and the last return was triggered inside of the function that causes the violation, the location of the return is used.

Also the formatting of location has been changed. Now a Location is a "single line". When printing the 2 surrounding lines are also shown.

def foo(flag: bool) -> int:
    print('Hello World')
    if flag:
        return 1
    else:
        return 'you stupid'

foo(False)

outputs

declared at: test-data/testTypesReturn.py:1
  1 > def foo(flag: bool) -> int:
  2 |     print('Hello World')
  3 |     if flag:
  4 |         return 1
  5 |     else:

caused by: test-data/testTypesReturn.py:6
  4 |         return 1
  5 |     else:
  6 >         return 'you stupid'
  7 | 
  8 | foo(False)

Copy link
Owner

@skogsbaer skogsbaer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@skogsbaer skogsbaer merged commit 24d7f9a into master Sep 30, 2021
@CodeSteak CodeSteak deleted the feature/15-locate-return branch October 24, 2021 14:29
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

Successfully merging this pull request may close these issues.

Blamed location is wrong when return type annotation is violated

2 participants