Skip to content
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.

String forward references not working as generic type parameters #1186

@jaens

Description

@jaens

When using "stringy" types such as List["SomeClass"] and a for loop over that (or any other operation that returns the element type), the element in the loop is not resolved as type SomeClass

Full repro example (see the comments for where the issue appears):

from typing import List

class Bar:
    def bar_method(self) -> int:
        return 1

def list_of_bars() -> List["Bar"]:
    return []

def no_string_list_of_bars() -> List[Bar]:
    return []

def a_single_bar() -> "Bar":
    return Bar()


def test():
    single = a_single_bar()

    single.bar_method()

    l = list_of_bars()

    for item in l: # Hover: Type of item is unresolved
        item.bar_method() # Go to definition does not work

    l2 = no_string_list_of_bars()

    for item2 in l2: # Type is resolved here
        item2.bar_method() # Ctrl+click works

image

image

Extension information:

Microsoft Python Language Server version 0.2.96.0

Name: Python
Id: ms-python.python
Description: Linting, Debugging (multi-threaded, remote), Intellisense, code formatting, refactoring, unit tests, snippets, and more.
Version: 2019.5.18875
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions