728x90

수많은 reportUnboundVariable error

이유를 탐색해보았다.

 

Reference

https://stackoverflow.com/questions/63388372/why-there-is-an-unbound-variable-error-warning-by-ide-in-this-simple-python-func

 

Why there is an unbound variable error warning by IDE in this simple python function

Very simple question, but I can't find the answer to it. My IDE vs code (pylance) give me the warning/hint for a being possibly unbound. Why is this? How do I fix it? def f(): for i in range(4)...

stackoverflow.com

 

➡️ Because range(4) might be something empty (if you overwrite the built-in range), in which case the loop body will never run and a will not get assigned. Which is a problem when it's supposed to get returned.

Maybe you can tell your IDE to ignore this and not show the warning.
Or assign some meaningful default to 'a' before the loop.

 

➡️ Meaning of 'Unbound'

  • A symbol that has not been given a value by assignment or in a function call is said to be “unbound.”
  • An unbound variable is one that is not within the scope of a quantifier.

 

➡️ 해결: while문 선언 전 'mid'에 대한 default value를 할당해주었다.

 

에러가 해결되었다

728x90

+ Recent posts