我是从PyCharm来的,想学习使用Emacs (Spacemacs)来设置Python。
PyCharm有一个称为Type Hinting的特性,它基本上允许指定类型,然后根据指定的类型获取提示。Python 3.5+有PEP 484 -- Type Hints,允许在没有注释的情况下指定类型。在PEP 484之前,指定类型是使用注释完成的。
Emacs中有这样的类型提示吗?
发布于 2017-02-27 21:48:35
在https://github.com/davidhalter/jedi/issues/858之后,Jedi 0.10.0添加了部分PEP484支持
发布于 2020-06-24 05:08:05
我在2020年遇到了这个问题,并发现有一些更好的工具来解决这个问题。光靠绝地可能得不到你想要的。相反,您可能希望使用elpy、flycheck flycheck-pycheckers、pyflakes和mypy的组合。
Elpy是Emacs Python IDE包。flycheck是一个用于Emacs的通用语法检查包。flycheck-pycheckers与flycheck一起工作,允许您使用多个Python语法检查器,因为pyflake不处理类型提示,mypy不处理常规语法-您需要同时使用这两种语法。
所以你的步骤应该是
安装pyflakes和mypy
use-package (我会将此操作的说明留给您)。;; flycheck
(use-package flycheck
:ensure t
:config
(global-flycheck-mode t)
;; note that these bindings are optional
(global-set-key (kbd "C-c n") 'flycheck-next-error)
;; this might override a default binding for running a python process,
;; see comments below this answer
(global-set-key (kbd "C-c p") 'flycheck-prev-error)
)
;; flycheck-pycheckers
;; Allows multiple syntax checkers to run in parallel on Python code
;; Ideal use-case: pyflakes for syntax combined with mypy for typing
(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
)
)
)
;; elpy
(use-package elpy
:after poetry
:ensure t
:config
(elpy-enable)
(add-hook 'elpy-mode-hook 'poetry-tracking-mode) ;; optional if you're using Poetry
(setq elpy-rpc-virtualenv-path 'current)
(setq elpy-syntax-check-command "~/.pyenv/shims/pyflakes") ;; or replace with the path to your pyflakes binary
;; allows Elpy to see virtualenv
(add-hook 'elpy-mode-hook
;; pyvenv-mode
'(lambda ()
(pyvenv-mode +1)
)
)
;; use flycheck instead of flymake
(when (load "flycheck" t t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode))
)
;; poetry
(use-package poetry
:ensure t)这个解决方案将帮助您在Emacs中设置Python语法和类型提示。
https://stackoverflow.com/questions/42486695
复制相似问题