Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intellisense doesn't work for a Class Instance returned from another Class Instance #647

Closed
mattdonders opened this issue Jan 29, 2018 · 4 comments
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@mattdonders
Copy link

Environment data

VS Code version: 1.19.3
Python Extension version: 0.9.1
Python Version: 3.5.1
OS and version: macOS 10.13.1

Actual behavior

I have an object called Game which contains a dictionary of two Team objects. The Game class has a method which returns a Tuple of these two teams based on one of their attributes.

Accessing the Team objects directly from the variable name that instantiated it allows for Intellisense to work correctly, but when I assign new values based on the return value of the function method above, Intellisense does not provide a list of attributes for those objects.

screenshot 2018-01-29 10 25 36

Expected behavior

I would expect that a variable that references an instance of an Object also return the attributes related to that object.

screenshot 2018-01-29 10 25 15

This is the method that returns the Team objects from the Game object -
screenshot 2018-01-29 10 41 36

Logs

Output from Python output panel
No logs in output panel.

Output from Console window (Help->Developer Tools menu)
No error logs in Console window.

Output from Terminal, showing memory addresses of referenced objects.

$ /usr/local/bin/python3 /Users/mattdonders/Development/python/devils-goal-twitter/scratchpad/oop-checkGameStatus.py --console --notweets
Preferred Team - <NHLGameEvents.Team object at 0x10410fba8>
Other Team - <NHLGameEvents.Team object at 0x1041f5438>

** Game Attributes **
<NHLGameEvents.Game object at 0x104217390>
teams: {'away': <NHLGameEvents.Team object at 0x10410fba8>, 'home': <NHLGameEvents.Team object at 0x1041f5438>}

** Home Team Attributes **
<NHLGameEvents.Team object at 0x1041f5438>
preferred: False

** Away Team Attributes **
<NHLGameEvents.Team object at 0x10410fba8>
preferred: True
@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. awaiting 1-verification labels Jan 29, 2018
@mattdonders
Copy link
Author

Worked on this code last night and it seems that this happens for instances of objects passed into a class that are not set within the __init__ of the object.

For example, if I create a new instance of another Object within __init__ I can reference that object and Intellisense works just fine, but if I have self.object = None or self.objects = [] within the __init__ then Intellisense isn't aware of the object type.

For example, changing my code to the below, allows me to reference game.home_team.<attribute> from anywhere in my code where previously game.teams["home"].<attribute> wouldn't work. The other thing as mentioned above is that since I create a new Period() and Shootout() instance within my Game object creation, I can reference those by game.period.<attribute> with Intellisense working just fine. I assume this is because Intellisense knows exactly what type of object this is.

class Game(object):
    """Holds all game related attributes - usually one instance created per game."""

    def __init__(self, game_type, date_time, game_state, venue,
                 home, away, preferred, live_feed):

        self.game_type = game_type
        self.date_time = date_time
        self.game_state = game_state
        self.venue = venue
        self._live_feed = live_feed
        self.home_team = home
        self.away_team = away

        # Not passed in at object creation time
        if preferred == "home":
            self.preferred_team = home
            self.other_team = away
        else:
            self.preferred_team = away
            self.other_team = home
    
         self.shootout = Shootout()
         self.period = Period()

@DonJayamanne
Copy link

@mattdonders

Please could you provide a code sample (or a repo) that we could use to replicate this issue.

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Feb 12, 2018
@brettcannon
Copy link
Member

Because it has been more than a month since we requested more info, I'm closing this issue. If you are able to provide the info later then please do so and we can re-open the issue.

@jgfet
Copy link

jgfet commented Jun 8, 2018

I am also experiencing this.
I have one module A with a class in it B, and a regular method C
B has both static and regular methods
In module D, I have a class E.
In E, I have attempted to reference an instance of B, and method C is not appearing in Intellisense.
Class E is referencing a collection of class B from module A, in a for loop within method F.

screen shot 2018-06-08 at 16 10 10

screen shot 2018-06-08 at 16 11 26

screen shot 2018-06-08 at 16 12 48

screen shot 2018-06-08 at 16 13 02

screen shot 2018-06-08 at 16 13 45

  • A = tidal
  • B = Jobdep
  • C = getVarCondition()
  • D = autosys
  • E = Job
  • F = getConditions()

Line 297 with jdrow - instance of B - Jobdep will not show name in list
screen shot 2018-06-08 at 16 24 18
screen shot 2018-06-08 at 16 24 32

Notice the static methods appeared, not the regular class instance one getVarCondition() or C....

screen shot 2018-06-08 at 16 32 45

Python 3.6.5 on Windows 2012RC2 64 bit.

I found the root of the problem for my case! An indentation issue!!!
Compare this change:
screen shot 2018-06-08 at 16 51 27

screen shot 2018-06-08 at 17 00 08

That change threw out quite a few errors in lint.
I subsequently changed the triple quoted string to comments too.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-intellisense LSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc. bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

5 participants