536 questions
-1
votes
1
answer
57
views
Incorrect type hint for name parameter in binary_var_list [closed]
The binary_var_list method in the docplex.mp.model API has an incorrect type annotation for the name parameter.
Current signature:
def binary_var_list(self, keys, lb=None, ub=None, name: type[str] = ...
0
votes
2
answers
53
views
python: vscode doesnt highlight direct import from module
When I attempt to import a module from a local package (from core import config), VSCode's syntax highlighting isn't working. When hovering over config, it shows "config: Any" (the editor ...
0
votes
1
answer
73
views
Python in vscode does not autocomplete or suggest built in class method
I am using vscode for Python dev. I have the Microsoft Extensions (Pylance, Python, Python Debugger, PythonEnviroments) installed and working.
The issue is when I try to make a metaclass in vscode ...
0
votes
0
answers
71
views
Pylance extension in VS code isn't providing autocomplete/intellisense for objects, has 2 illegal state - object is disposed errors
Title pretty much says it all. Autocomplete works fine for variables I declare in the main script body, but when I instantiate an object of a class, autocomplete doesn't predict any of the class's ...
0
votes
1
answer
176
views
Python language features do not work with libraries installed in Poetry local virtual environment (.venv)
I have a Python Poetry project. Visual Studio Code features like auto-import and auto-complete do not work for the project dependency libraries. Pylance (the Python language server for Visual Studio ...
1
vote
1
answer
73
views
How to fix Visual Studio Code tensorflow keras imports highlighting and suggestions?
So I'm working through tensorflow, I got into it recently, and I dont know the library well. I'd like to rely on suggestions on what to type, to be able to check what parameters are there to functions,...
-1
votes
1
answer
742
views
Type hint warning `"keys" is not a known attribute of "None"` for `Optional` in Pylance [duplicate]
Recently Pylance has started to add red underlines in my code. I've managed to fix most of it, but I have problems with Optional typing:
def realms(testenv:str, active:bool=True) -> Optional[Dict]:
...
1
vote
0
answers
81
views
Pylance is not recognizing "Methods:" section in a Python class docstring
Consider this Python class with docstring:
class TestClass:
'''
Summary line of docstring
Additional lines of docstring.
Attributes:
attr1 (int): this is the desc of a public ...
0
votes
0
answers
170
views
Pylance: "Variable not allowed in type expression" for torch.Tensor return type with from __future__ import annotations (Python 3.12, PyTorch 2.5)
I'm encountering a Pylance(reportInvalidTypeForm) error when using torch.Tensor as a return type hint in my PyTorch nn.Module subclasses. This happens even though from future import annotations is the ...
1
vote
0
answers
219
views
Make Pylance suggest all imports for my code when working in a separate directory
With VSCode Pylance, many import suggestions are missing when working under these conditions:
Package installed in editable mode
I'm working in a separate directory
Original package does not contain ...
0
votes
0
answers
62
views
Pylance & Pylint report “could not be resolved” / “no-member” for a valid PyPI package in VSCode virtual environment
What configuration changes are needed in VSCode (or in my project layout) to make Pylance and Pylint recognize the installed cowsay package and its members? Is there a best practice for structuring ...
0
votes
0
answers
39
views
VSCode pylance not detecting matplotlib and mpi4py
This is the problem in VSCode:
import matplotlib.pyplot as plt # Import "matplotlib.pyplot" could not be resolved from sourcePylancereportMissingModuleSource
from mpi4py import MPI # No ...
0
votes
1
answer
390
views
Pylance slows my VSCode's autocomplete to as much as 5-10 sec of wait for the dropdown
I discovered that Pylance was the source of my VSCode's autocomplete's slowness after following Visual Studio Code Intellisense is very slow - Is there anything I can do? and disabling all my ...
0
votes
0
answers
37
views
Pylance Local Installed Module Cannot Resolve Imports Inside Package
In VS Code I have a little python (Python 3.11.9) module I'm building beside my main code. The module works fine and runs without issue. I've installed it in edit mode via pip install -e .
Still ...
0
votes
1
answer
307
views
How to resolve type checking error in Django when accessing Serializer.validated_data
I'm encountering a type checking error in VSCode with Pylance (pyright) when accessing serializer.validated_data["code"] in a Django project. The errors are:
"__getitem__" method ...
0
votes
0
answers
146
views
VS Code Pylance does not show parameter-specific hints from a module
Actual behaviour: the docstring is missing…
Expected behaviour: the parameter-specific docstring is shown (imagine this in my code instead, not just in the module itself as seen below)
Pylance does ...
0
votes
1
answer
139
views
Ignore specific file for linting in Visual Studio Code
So I want to ignore the errors for my jupyter notebook code, since Im just using it to store code which I copy paste into my terminal. I tried to to edit the settings and even tried to change the ...
2
votes
1
answer
211
views
Is there a way to make vscode showing when a local variable shadows a global one in Python code?
I'm using VSCode and Pylance. Consider the following example of a variable defined and initialized in outer scope being reassigned in inner scope:
number: int = 0
def change_number() -> None
...
0
votes
0
answers
143
views
Enabling autocomplete for variables for Python in VSCode
I'm using Visual Studio Code version 1.96.2 on macOS 14.4.1. This is the latest version of VSCode currently available.
The extensions I have installed (and reinstalled) are:
Pylance
Microsoft's ...
2
votes
1
answer
258
views
Pylance use Django V4 after Upgrading to Django V5
I have a model like this:
class Test(models.Model):
a = models.TextField(null=True, blank=True)
b = models.TextField(null=True, blank=True)
class Meta:
constraints = [
...
1
vote
1
answer
131
views
Docstring formatting not working in VSCode
Minor issue. Some days ago, docstrings would be formatted so that when I hover over them, "Args" (Google-style) and "Returns" would be in bold, as well as the names of the ...
0
votes
0
answers
47
views
Unable to auto-import libraries in python and jupyter notebook files
I cannot for the life of me fathom why VS code is not displaying import suggestions in a popup or auto-importing missing packages as it should be doing.
VSCode version: 1.95.3
Pylance version: v2024....
1
vote
1
answer
420
views
Pylance failing to resolve import of libraries in a devcontainer in Linux
I have a Python project in Ubuntu 24.04.1 LTS and I have a DevContainer in VSC with Debian GNU/Linux 11, the problem is that Pylance is flagging import streamlit as st with Import "streamlit"...
1
vote
3
answers
336
views
Make class attribute private outside API for users, but public inside API for developers
I am having trouble dealing with classes wherein I have classes whose attributes and methods I want to access in my API code, but not have those attributes and methods exposed to the user who is using ...
0
votes
1
answer
92
views
VSCode, Pylance how to get proper help popup?
I enhanced a class by adding some few methods from another class (Jira's class from atlassian-python package)
My class is called JiraExtended.
Original methods from the class display this way:
The ...