0

I want the IDE (pycharm) to know the type of an varliable

class phone:

    def __init__(self,):
        self.device = None
    def connect(self,):
        self.device = samsung_object()

Now the IDE don't know the functions/vars used for device. I want that in init time it will be a samsung object type.

2
  • so call self.connect()? Commented Aug 9, 2019 at 15:28
  • you could add self.connect() at the end of your __init__ function or call new_phone=phone().connect() when you instantiate the new_phone variable Commented Aug 9, 2019 at 15:32

1 Answer 1

2

Converting comments into code for you :)

This will works and PyCharm knows the type too..

class Samsung:
    def foo(self): pass

class Phone:
    def __init__(self,):
        self.device = Samsung()
    def connect(self,):
        self.device.foo() # pycharm suggest foo
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.