microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 767 forks source link

pylance loses link to a object if it was returned by fixture #5718

Open Akopov4 opened 6 months ago

Akopov4 commented 6 months ago

Environment data

Code Snippet

class Cl_1:
    def __init__(self):
       pass
    def some_f1:(self):
       pass

class Cl_2:
    def __init__(self):
         self.obj1=Cl_1()

     def some_f2:(self):
       pass

@fixture
def fixt_1():    
    yield Cl_2()

@fixture
def fixt_2(fixt_1):     
     yield fixt_1

def test_some_test(fixt_2):
      fixt_2.some_f2()
      fixt_2.obj1.some_f1

Repro Steps

  1. XXX

Expected behavior

Test run ok. When I press CTRL+ left mouse click in any of the : fixt_2.some_f2() fixt_2.obj1.some_f1()

I jump into declaration of the appropriate function

Actual behavior

Test runs ok. Inside my test: (function) some_f2: Unknown (function) obj1: Unknown

Logs

vscode_log.txt

XXX

Requirments

requirements.txt

XXX
Akopov4 commented 6 months ago

I did some experiments, this issue is reproducible when the inlay hints are not visible: "editor.inlayHints.enabled": "offUnlessPressed" or "editor.inlayHints.enabled": "off"

bschnurr commented 6 months ago

thank you for the issue.

yes there seems to be an issue with fixtures that use yield to return a generator.

there was a slight type in your def somef1:(self) to def somef1(self)

if you set typecheckingmode to basic you should see the errors

for now try adding annotations to the fixture usage

from pytest import fixture

class Cl_1:
    def __init__(self):
       pass
    def some_f1(self):
       pass

class Cl_2:
    def __init__(self):
         self.obj1=Cl_1()

    def some_f2(self):
       pass

@fixture
def fixt_1():    
    yield Cl_2()

@fixture
def fixt_2(fixt_1: Cl_2):     
     yield fixt_1

def test_some_test(fixt_2: Cl_2):
      fixt_2.some_f2()
      fixt_2.obj1.some_f1

on second thought maybe my annotation is wrong for this def test_some_test(fixt_2: Cl_2):

Akopov4 commented 1 month ago

Hello, is there any movement in this investigation?

rchiodo commented 1 month ago

Sorry this hasn't been investigated yet.