View Single Post
Old 08-06-2025, 12:54 PM   #1
sgmoore
Zealot
sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.sgmoore ought to be getting tired of karma fortunes by now.
 
Posts: 138
Karma: 642206
Join Date: Mar 2021
Device: Kindle Voyage
Avoiding "is not defined" errors with Pylance and VSCode

Does anyone use Microsoft's Pylance static type checker in VSCode and know how to disable this type of error.

For example, given the following snippet

Code:
# noinspection PyUnreachableCode
if False :
    load_translations = _ = ngettext = lambda x=None, y=None, z=None: x

load_translations()
The first few lines are enough to stop ruff and mypy from complaining about the method call but not Pylance which displays an error like

"load_translations" is not defined Pylance (reportUndefinedVariable)

I know I have three options
1) Disable pylance
2) Disable this type of error across the whole project
3) Pollute the codebase by adding "# type: ignore" to hundreds of lines.

But I would prefer not to have do any of these and was wondering if there was a better way?
sgmoore is offline   Reply With Quote