0

The example warning I am getting is Item "None" of "Optional[IO[bytes]]" has no attribute "close"], as making the line bold and red. This usually occurs if Python cannot detect the type or its function.

The way I imported: from subprocess import PIPE, STDOUT, CalledProcessError, Popen, check_output


enter image description here

  • Using # NOQA, # flake8: noqa did not help, represented as flycheck-warning'.

I still want to see the warning for unused imports but if I use # noqa I want them to go away.


Setup file, complete section for flycheck is here: https://gist.github.com/avatar-lavventura/e8713d871696538bf59a0c0245a878ec :

(use-package flycheck-pycheckers
  :after flycheck
  :ensure t
  :init
  (with-eval-after-load 'flycheck
    (add-hook 'flycheck-mode-hook #'flycheck-pycheckers-setup)
    )
  (setq flycheck-pycheckers-checkers
    '(
      mypy3
      pyflakes
      )
    )
  )

In my configuraiton I believe flake8 is enabled.

Elpy Configuration

Emacs.............: 26.3
Elpy..............: 1.34.0
Virtualenv........: venv (/home/alper/venv)
Interactive Python: python3 3.7.5 (/home/alper/venv/bin/python3)
RPC virtualenv....: rpc-venv (/home/alper/.emacs.d/elpy/rpc-venv)
 Python...........: python 3.7.5 (/home/alper/.emacs.d/elpy/rpc-venv/bin/python)
 Jedi.............: 0.17.2
 Rope.............: 0.16.0
 Autopep8.........: 1.5.4
 Yapf.............: 0.30.0
 Black............: 20.8b1
Syntax checker....: flake8 (/home/alper/.local/bin/flake8)

Update:

Output of flycheck-verify-setup:

Syntax checkers for buffer Driver.py in python-mode:

First checker to run:

  python-flake8
    - may enable:         yes
    - executable:         Found at /Users/alper/venv/bin/python3
    - configuration file: Not found
    - `flake8' module:    Found at "/Users/alper/venv/lib/python3.7/site-packages/flake8/__init__.py"
    - next checkers:      python-mypy, python-pylint

Checkers that may run as part of the first checker's chain:

  python-pylint
    - may enable:         yes
    - executable:         Found at /Users/alper/venv/bin/pylint
    - configuration file: Found at "/Users/alper/.pylintrc"
    - next checkers:      python-mypy

  python-mypy
    - may enable:         yes
    - executable:         Found at /Users/alper/venv/bin/mypy
    - configuration file: Found at "/Users/alper/eBlocBroker/setup.cfg"

Checkers that could run if selected:

  python-pycompile  select
    - may enable:    yes
    - executable:    Found at /Users/alper/venv/bin/python3
    - next checkers: python-mypy

Checkers that are compatible with this mode, but will not run until properly configured:

  python-pyright (automatically disabled) reset
    - may enable: no
    - executable: Not found

Flycheck Mode is enabled.  Use C-u C-c ! x to enable disabled checkers.

--------------------

Flycheck version: 32snapshot (package: 20201023.1716)
Emacs version:    26.3
System:           x86_64-apple-darwin19.6.0
Window system:    nil

Output of M-x -> describe-variable AND flycheck-checkers:

flycheck-checkers is a variable defined in ‘flycheck.el’.
Its value is
(python-pycheckers solium-checker solidity-checker ada-gnat asciidoctor asciidoc awk-gawk bazel-buildifier
c/c++-clang c/c++-gcc c/c++-cppcheck cfengine chef-foodcritic coffee coffee-coffeelint coq css-csslint
css-stylelint cuda-nvcc cwl d-dmd dockerfile-hadolint elixir-credo emacs-lisp emacs-lisp-checkdoc ember-template
erlang-rebar3 erlang eruby-erubis eruby-ruumba fortran-gfortran go-gofmt go-golint go-vet go-build go-test
go-errcheck go-unconvert go-staticcheck groovy haml handlebars haskell-stack-ghc haskell-ghc haskell-hlint
html-tidy javascript-eslint javascript-jshint javascript-standard json-jsonlint json-python-json json-jq jsonnet
less less-stylelint llvm-llc lua-luacheck lua markdown-markdownlint-cli markdown-mdl nix nix-linter opam perl
perl-perlcritic php php-phpmd php-phpcs processing proselint protobuf-protoc protobuf-prototool pug puppet-parser
puppet-lint python-flake8 python-pylint python-pycompile python-pyright python-mypy r-lintr racket rpm-rpmlint
rst-sphinx rst ruby-rubocop ruby-standard ruby-reek ruby-rubylint ruby ruby-jruby rust-cargo rust rust-clippy
scala scala-scalastyle scheme-chicken scss-lint scss-stylelint sass/scss-sass-lint sass scss sh-bash
sh-posix-dash sh-posix-bash sh-zsh sh-shellcheck slim slim-lint sql-sqlint systemd-analyze tcl-nagelfar terraform
terraform-tflint tex-chktex tex-lacheck texinfo textlint typescript-tslint verilog-verilator vhdl-ghdl
xml-xmlstarlet xml-xmllint yaml-jsyaml yaml-ruby yaml-yamllint)
Original value was
(ada-gnat asciidoctor asciidoc awk-gawk bazel-buildifier c/c++-clang c/c++-gcc c/c++-cppcheck cfengine
chef-foodcritic coffee coffee-coffeelint coq css-csslint css-stylelint cuda-nvcc cwl d-dmd dockerfile-hadolint
elixir-credo emacs-lisp emacs-lisp-checkdoc ember-template erlang-rebar3 erlang eruby-erubis eruby-ruumba
fortran-gfortran go-gofmt go-golint go-vet go-build go-test go-errcheck go-unconvert go-staticcheck groovy haml
handlebars haskell-stack-ghc haskell-ghc haskell-hlint html-tidy javascript-eslint javascript-jshint
javascript-standard json-jsonlint json-python-json json-jq jsonnet less less-stylelint llvm-llc lua-luacheck lua
markdown-markdownlint-cli markdown-mdl nix nix-linter opam perl perl-perlcritic php php-phpmd php-phpcs
processing proselint protobuf-protoc protobuf-prototool pug puppet-parser puppet-lint python-flake8 python-pylint
python-pycompile python-pyright python-mypy r-lintr racket rpm-rpmlint rst-sphinx rst ruby-rubocop ruby-standard
ruby-reek ruby-rubylint ruby ruby-jruby rust-cargo rust rust-clippy scala scala-scalastyle scheme-chicken
scss-lint scss-stylelint sass/scss-sass-lint sass scss sh-bash sh-posix-dash sh-posix-bash sh-zsh sh-shellcheck
slim slim-lint sql-sqlint systemd-analyze tcl-nagelfar terraform terraform-tflint tex-chktex tex-lacheck texinfo
textlint typescript-tslint verilog-verilator vhdl-ghdl xml-xmlstarlet xml-xmllint yaml-jsyaml yaml-ruby
yaml-yamllint)
9
  • 1
    Pyflakes doesn't appear to support the # NOQA (or similar) syntax for ignoring errors. See (stackoverflow.com/questions/5033727/…) and (github.com/PyCQA/pyflakes/issues/431). You likely want to use flake8 instead of pyflakes as a syntax checker, which will allow your # NOQA comments to work again.
    – D. Gillis
    Jul 8 '20 at 5:53
  • Hm as I understand I have to run pyflakes under flake8. I think I am already using flake8 so I just remove pyflakes from .emacs and pip packages should resolve it
    – alper
    Jul 8 '20 at 12:02
  • @D.Gillis not sure but I still have the same error even pyflakes is not defined in my .emacs file and seems like flake8 is enables: Syntax checker....: flake8 (/home/user/.local/bin/flake8)
    – alper
    Dec 7 '20 at 0:41
  • 1
    I think the warning you are getting is coming from some kind of static analyzer (such as jedi or mypy) other than flake8, which would explain why # NOQA doesn't work here. Unless it has changed recently, flake8 does not look at types, so it wouldn't be able to return a warning about an AttributeError. If the error is from mypy, adding the comment # type: ignore may work (see: stackoverflow.com/questions/49220022). If it does not work, can you provide the values of elpy-syntax-checker,python-check-command, and python-flymake-command in the buffer where this occurs?
    – D. Gillis
    Dec 7 '20 at 7:29
  • Thanks # type: ignore works on my end.For python-check-command I am having /home/alper/venv/lib/python3.7/site-packages is in the MYPYPATH. Please remove it.
    – alper
    Dec 8 '20 at 11:15
1

You have some problem(s) in your code - you did not show how you imported the subprocess module - my guess is you just written import subprocess, which is not what you want. Instead use from subprocess import popen, PIPE.

The reason is if you do not import PIPE, stdout is not declared/recognised, so p1.stdout.close() does not exist; this also explains the message Item "None" of "Optional[IO[bytes]]" has no attribute "close".

3
  • I have tried from subprocess import popen, PIPE but still facing with the same error message. github.com/jacktasia/dumb-jump can jump into right close() function but seems like its not detected by the flake8
    – alper
    Feb 8 at 20:53
  • Try from command line my suggestion posted on Dec 11'20 in comments on your question and see the result. BTW, seems to me flake8 is not inserted in flycheck-pycheckers-checkers. Take into account the #noqa must be completed with error numbers, there are many cases when it is not recognised; there is also a flake8-noqa package installable with pip which checks for correct #noqa. One last word: if still problems with this, a wise decision is to install lsp + server python-language-server (with pip).
    – Ian
    Feb 9 at 15:48
  • # type: ignore works on my end but still # noqa does not with all the suggestions I tried :-(
    – alper
    Feb 10 at 11:39

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.