I am using flycheck for for Python. For global files that I set using ( globals()['variable']), and later used, it gives the following warning message: undefined name <variable> [F821]


globals()['var1'] = "hello_world"
print(var1) # undefined name 'fID' [F821]

It underlines and colors it with red color.

enter image description here

Added lines to .emacs

(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)
(setq-default flycheck-flake8-maximum-line-length 160)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(setq flycheck-emacs-lisp-load-path 'inherit)
  • 2
    There are nothing to do about it on Emacs side. It's from code checker. flake8 I guess.
    – muffinmad
    Nov 25 '19 at 10:23
  • @muffinmad Should I ask this question on stackoverflow refering to flake8?
    – alper
    Nov 25 '19 at 16:18
  • Yes, I think it will help solve your issue.
    – muffinmad
    Nov 26 '19 at 8:06
  • I have asked but community has removed my question :( @muffinmad
    – alper
    Jan 11 '20 at 20:19

A turnaround is to declare the variable.

# Make flake8 happy
if "var1" not in globals():
    var1 = None

globals()['var1'] = "hello_world"

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.