0

I am getting following warning message for the following code: F821 undefined name 'variable'. // variable becomes color red.

#!/usr/bin/env python3

def doo():
    print(variable)  # <= F821 undefined name 'variable'

if __name__ == "__main__":
    doo()

But if I create variable in __main__ the warning message is gone, but still variable in undefined under the doo() function.

#!/usr/bin/env python3

def doo():
    print(variable)


if __name__ == "__main__":
    variable = 100
    doo()

[Q] Is there any way to prevent this error message where main's scope would be ignore in functions' scopes?


Setup:

(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
(require 'flycheck)
(require 'flycheck-mypy)

(add-hook 'python-mode-hook 'flycheck-mode) ;(add-hook 'after-init-hook #'global-flycheck-mode)
(add-hook 'python-mode-hook
          (lambda ()
            (setq flycheck-python-pylint-executable "~/venv/bin/pylint")
            (setq flycheck-pylintrc "~/.pylintrc")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.