Variable used before definition
See original GitHub issueEnvironment 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:
- Create a new project,
python3 -m venv new/venv
. - Insert code into
new/index.py
. - Lint.
Logs
Output for Python
in the Output
panel (View
→Output
, 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:
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:11 (3 by maintainers)
Top Results From Across the Web
'Variable' was used before it was defined - Stack Overflow
I pasted the first code snippet into JSLint on the home page of jslin.com, got the JSLint warns that it is used before...
Read more >no-use-before-define - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Can I use a JavaScript variable before it is declared?
Yes, you can use a JavaScript variable before it is declared, with a technique called hoisting. The parser reads through the complete ...
Read more >Variable '<variablename>' is used before it has been assigned ...
Variable '<variablename>' is used before it has been assigned a value. A null reference exception could result at run time.
Read more >'{a}' was used before it was defined - JSLint Error Explanations
If it does run in strict mode, it will generate a reference error as it's illegal to assign a value to an undefined...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@phwh reported in https://github.com/Microsoft/python-language-server/issues/399 .
Having a similar issue… It’s really frustrating.
Doing some very basic DRF stuff with django rest and these things keep popping up 😦