Python Forum

Full Version: declaring object parameters with type
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I pass an object in as a parameter to a function, is there a way to specify in the function declaration what type the parameter is so that I can see its properties as I type. I have a class called Browser
br=Browser()
br.<argument and type display here>
print(other_function(br))
other_function(brw):
    x=brw.<here I get nothing>
    return True
Is there any way to do a sort of early binding. What I have been doing is to over-shadow the parameter with a local instance of its class, then when I am done coding the function, I delete it
You can use type annotations
def other_function(brw: Browser):
    x = brw <auto complete now knows to look at Browser>
This will also help when when calling other_function
other_function(<auto complete will tell you a Browsere object is expected
(Dec-13-2022, 07:45 PM)deanhystad Wrote: [ -> ]You can use type annotations
def other_function(brw: Browser):
    x = brw <auto complete now knows to look at Browser>
This will also help when when calling other_function
other_function(<auto complete will tell you a Browsere object is expected

Awesome. Thank you