False positive builtin name detection in exception handler body
See original GitHub issueDescribe 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)
importstatements- 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)
forloops and comprehensionswith ... as ...except ... as ...- And pattern matching in 3.10 may also bind names
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (12 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It’s great!
Great. Then I think 4a6a94e is ready. Thanks again.