Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 14, 2022. It is now read-only.
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Variable used before definition #475

Copy link
Copy link
@brettcannon

Description

@brettcannon
Issue body actions

@azdanov commented on Sat Dec 08 2018

Environment data

  • VS Code version: 1.29.1 (1.29.1)
  • Extension version (available under the Extensions sidebar): 2018.11.0
  • OS and version: macOS Mojave 10.14.1 (18B75)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.7.1 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: -

Expected behaviour

When running provided code snippet there should be no warning.

from typing import Dict

fallbackName: Dict[str, str] = {"firstName": "First", "lastName": "Last"}

NAME = " ".join(str(x) for x in fallbackName.values())

print(f"Hi, {NAME}!")

Actual behaviour

A warning is generated: 'fallbackName' used before definition

{
	"resource": "/Users/_____/Projects/python/sandbox/index.py",
	"owner": "_generated_diagnostic_collection_name_#0",
	"code": "use-before-def",
	"severity": 4,
	"message": "'fallbackName' used before definition",
	"source": "Python",
	"startLineNumber": 5,
	"startColumn": 33,
	"endLineNumber": 5,
	"endColumn": 45
}

Additional Info

This does not happen when type hinting is removed:

FALLBACK_NAME = {"first_name": "First", "last_name": "Last"}

NAME = " ".join(str(x) for x in FALLBACK_NAME.values())

print(f"Hi, {NAME}!")

Steps to reproduce:

  1. Create a new project, python3 -m venv new/venv.
  2. Insert code into new/index.py.
  3. Lint.

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

Starting Microsoft Python language server.
Microsoft Python Language Server version 0.1.66.0
Initializing for /Users/_____/Projects/python/sandbox/venv/bin/python
##########Linting Output - prospector##########
{
  "summary": {
    "started": "2018-12-08 12:13:01.666245",
    "libraries": [],
    "strictness": "from profile",
    "profiles": ".prospector.yaml, full_pep8, doc_warnings, strictness_veryhigh, no_member_warnings",
    "tools": [
      "dodgy",
      "mccabe",
      "mypy",
      "pep257",
      "pep8",
      "profile-validator",
      "pyflakes",
      "pylint"
    ],
    "message_count": 0,
    "completed": "2018-12-08 12:13:02.171521",
    "time_taken": "0.51",
    "formatter": "json"
  },
  "messages": []
}

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

 INFO no standard startup: not a new window
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Create file systemwatcher with pattern */python
console.ts:134 [Extension Host] Python Extension: Create file systemwatcher with pattern */*/python
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Register Intepreter Watcher, Arg 1: {"$mid":1,"fsPath":"/Users/_____/Projects/python/sandbox","external":"file:///Users/_____/Projects/python/sandbox","path":"/Users/_____/Projects/python/sandbox","scheme":"file"}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Create file systemwatcher with pattern */python
console.ts:134 [Extension Host] Python Extension: Create file systemwatcher with pattern */*/python
console.ts:134 [Extension Host] Python Extension: Display locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Notify locators are locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Detected refreshing of Interpreters, Arg 1: {}, Return Value: 
console.ts:134 [Extension Host] Python Extension: Build the workspace interpreter watcher, Arg 1: {"$mid":1,"fsPath":"/Users/_____/Projects/python/sandbox","external":"file:///Users/_____/Projects/python/sandbox","path":"/Users/_____/Projects/python/sandbox","scheme":"file"}, Return Value: UNABLE TO DETERMINE VALUE
console.ts:134 [Extension Host] Python Extension: Register Intepreter Watcher, Arg 1: undefined, Return Value: 
console.ts:134 [Extension Host] Python Extension: Build the workspace interpreter watcher, Arg 1: undefined, Return Value: UNABLE TO DETERMINE VALUE
console.ts:134 [Extension Host] Python Extension: Get language server folder name, , Return Value: "languageServer.0.1.66"
6console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Hide locator refreshing progress, , Return Value: 
console.ts:134 [Extension Host] Python Extension: All locators have completed locating, , Return Value: 
console.ts:134 [Extension Host] Python Extension: Checking whether locactors have completed locating, , Return Value: 

@yehorb commented on Sat Dec 08 2018

I have a similar issue with my Python.
VS Code version: 1.29.1 (1.29.1)
Extension version (available under the Extensions sidebar): 2018.11.0
OS and version: Ubuntu 18.04.1 LTS
Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.7 64-bit
Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
Relevant/affected Python packages and their versions: not relevant

Issues disappear if you reload window, but reappear if I make even the slightest edit to the code written. Sometimes they appear as I type (e.g. I type "return True" and issues are " 're' used before definition", " 'ret' used before definition" and so on).

Issue appears to occur more in longer files.

screenshot from 2018-12-09 00-47-41
screenshot from 2018-12-09 00-47-53


@azdanov commented on Sat Dec 08 2018

@yehorb Could you create a minimal Github repo with a reproducible error? It will help a lot in fixing this issue.

In my case, this happens because of typing.


@yehorb commented on Mon Dec 10 2018

Here:
https://github.com/yehorb/VSCode-use-before-def-bug

This is the output I get:
screenshot from 2018-12-10 12-59-08
screenshot from 2018-12-10 12-59-19
screenshot from 2018-12-10 12-59-32
screenshot from 2018-12-10 12-59-51
screenshot from 2018-12-10 13-00-12
screenshot from 2018-12-10 13-00-32
screenshot from 2018-12-10 13-00-38
screenshot from 2018-12-10 13-00-46


@azdanov commented on Mon Dec 10 2018

@yehorb Awesome, thanks! Now it's just waiting for a maintainer to triage this issue. 🤷‍♂️

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.