Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

String forward references not working as generic type parameters #1186

Closed
jaens opened this issue Jun 8, 2019 · 1 comment · Fixed by #1441
Closed

String forward references not working as generic type parameters #1186

jaens opened this issue Jun 8, 2019 · 1 comment · Fixed by #1441
Assignees
Labels
bug Something isn't working feature: analysis
Milestone

Comments

@jaens
Copy link

jaens commented Jun 8, 2019

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

@jaens
Copy link
Author

jaens commented Jun 13, 2019

Looks like this applies to any operation on generic types, not just for loops (eg. indexing).

@jaens jaens changed the title String forward references not working as generic type parameters in for String forward references not working as generic type parameters Jun 13, 2019
@MikhailArkhipov MikhailArkhipov added bug Something isn't working feature: analysis labels Aug 8, 2019
@MikhailArkhipov MikhailArkhipov added this to the August 2019.1 milestone Aug 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working feature: analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants