question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

False positive builtin name detection in exception handler body

See original GitHub issue

Describe the bug Names in exception handler body could be incorrectly determined as builtin features used.

To Reproduce

File:

for file in ['foo']:
    try:
        1 / 0
    except ZeroDivisionError:
        print(file)

Result:

Detecting python files..
Analyzing using 8 processes..
2.0, !3      test.py
  print(expr) requires 2.0, 3.0
  L5 C14: 'file' member requires 2.0, !3

Minimum required versions: 2.0
Incompatible versions:     3

Expected behavior

Should not detect file as Python 2 builtin file member.

Environment

  • Vermin version: 1.1.1

Additional context This is due to commit bd9ded9 for addressing #45. To match the current detection heuristics (outside of exception handlers), we should not look for builtin exceptions in the body attribute of an ExceptHandler node, but only look for them inside the type attribute.

It would also be better to recognize file as a user-defined name in this case. There are many kinds for syntactic structures which create new variables (bind names) in Python:

  • Assignment (regular assignment, augmented assignment, annotated assignment, walrus)
  • import statements
  • Function and class definitions (the function/class name is a variable in the containing scope)
  • Function argument list (an argument is a local variable of the function)
  • for loops and comprehensions
  • with ... as ...
  • except ... as ...
  • And pattern matching in 3.10 may also bind names

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
gousaiyangcommented, May 2, 2021

It’s great!

1reaction
netromdkcommented, May 2, 2021

Great. Then I think 4a6a94e is ready. Thanks again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle errors in ASP.NET Core | Microsoft Learn
By Tom Dykstra. This article covers common approaches to handling errors in ASP.NET Core web apps. See Handle errors in ASP.
Read more >
Exception Handling - UTK EECS
Exception Handling. I. Basic Concepts A. Exception: 1. An unusual event, either erroneous or not 2. Detectable by either hardware or software 3....
Read more >
How to fix Python KeyError Exceptions in simple steps?
Know about Python KeyError Exception. And learn how to handle exceptions in Python. A detailed guide to Errors and Exceptions in Python.
Read more >
typescript-eslint/no-unused-vars false positive in type ...
And we have @typescript-eslint/no-unused-vars error in string with type declaration, which says 'name' is defined but never used. And eslint ...
Read more >
10.2 Exceptions - Racket Documentation
Every exn structure value has a message field that is a string, the primitive error message. The default exception handler recognizes exception values...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found