Skip to content

return of Any being reported as possibly unbound (via VS Code's pylance) #1362

Answered by erictraut
jecluis asked this question in Q&A
Discussion options

You must be logged in to vote

Annotating a return type with Any quite common, so that in itself is not unusual. There must be something else about your configuration or code file that is resulting in this problem.

I suspect it's a problem in the way you are importing `Any. Perhaps you are conditionally importing that symbol? Something like this:

test: bool = False

if test:
    from typing import Any

def foo() -> Any:
    return 123

A few follow-up questions:

  1. Where are you importing Any from?
  2. Is the import statement at the top level of the module or within an if/else or try/except statement?
  3. If you copy the foo function into its own ".py" file (and add an import statement), do you still see the problem?
  4. Is the symbol

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@jecluis
Comment options

Comment options

You must be logged in to vote
1 reply
@jecluis
Comment options

Answer selected by jecluis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants