[Python] Is there a way to make vscode showing when a local variable shadows a global one in...

Discussão em 'Python' iniciado por Stack, Janeiro 27, 2025.

  1. Stack

    Stack Membro Participativo

    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
    number: int = 10


    When I move the mouse over the local number variable, the lsp tells me that "number is not accessed". I would like for it to also tell me that it's reassigning number from outer scope.

    PyCharm has this feature. As far as I can tell, VSCode with Pylance installed does not provide information about variable reassignment in inner scopes, at least out of the box/as default. Is there a configuration available for the lsp to highlight/signal/mention that variable reassignment is taking place?

    Continue reading...

Compartilhe esta Página