VSCode 1.30.2(Mojave)Python无变量提示问题求助
Hey there, let's tackle this variable type hint issue you're facing with Python 2.7.15 on VSCode 1.30.2 under Mojave. First off, it's important to note that both VSCode 1.30.2 (a pretty old release from late 2018) and Python 2.7 (which reached end-of-life years ago) have limited support for modern type hint features compared to newer versions. That said, here are some targeted fixes to try:
Revert the
python.jediEnabledsetting: You mentioned setting this tofalsedidn't help, but switching back to"python.jediEnabled": truemight actually work better. Back in VSCode 1.30.2, Microsoft's own language server was still relatively new and had poor compatibility with Python 2.7, whereas Jedi (the default at the time) had more mature support for older Python versions.Add manual type comments: Since Python 2.7 doesn't natively support type annotation syntax (that came in Python 3.5+), VSCode can't always infer variable types automatically. You can help the editor out by adding type hints via comments, like this:
user_name = "Jarvis" # type: str user_name. # Now you should see string-related method suggestionsThe old Python extension and IntelliCode should pick up these comments and show relevant hints.
Enable Pylint with type checking: Make sure Pylint is installed (
pip install pylintfor your Python 2.7 environment) and enable it in VSCode settings:"python.linting.pylintEnabled": true, "python.linting.pylintArgs": ["--enable=W0614", "--type-check"]Pylint can help infer types and trigger better hinting in older VSCode versions for Python 2.
Try upgrading VSCode (if possible): While Mojave (macOS 10.14) doesn't support the latest VSCode releases, you can upgrade to VSCode 1.75.1 (the last version compatible with 10.14). This newer (but still compatible) version has better Python 2.7 support in its Python extension, which might resolve the type hint issue without breaking your system compatibility.
I know you've already searched Google for solutions, but these are specific workarounds tailored to your exact setup—old VSCode, Python 2.7, and Mojave. Give them a shot and see if any of them get those variable hints working for you!
内容的提问来源于stack exchange,提问作者Jarvis

