Bind API

On this page

Introduction

qi.bind allow specifying types for bound methods. By default methods parameters are of type AnyValue and always return an AnyValue.

With qi.bind you can specify which types the function really accept and return. With qi.nobind you can hide methods.

Reference

qi. bind ( returnType = None , paramsType = Node , methodName = None )

This function decorator allows specifying types for bound methods. You can use methodName to rename the method.

qi. nobind ( )

This function decorator will prevent the function from being bound. (exported)

qi. singleThreaded ( )

This class decorator specifies that methods of this class will be run one at a time. That means that two methods wont never run at the same time. So you dont have to care about thread safeness. This is the default.

qi. multiThreaded ( )

This class decorator specifies that all methods in the class can be run concurrently. You will have to protect your methods for threadsafety.

Examples

How to have two functions with the same name?

This works for methods with different arguments types, or with different arguments count.


             
              class MyFoo:

  @qi.bind(paramsType=(qi.Int32,) , methodName="bar")
  def bar1(self, arg):
    pass

  @qi.bind(paramsType=(qi.String,) , methodName="bar")
  def bar2(self, arg):
    pass

             
            

How to specify the return type of a method?


             
              class MyFoo:

  @qi.bind(returnType=qi.String)
  def bar(self, arg):
    pass

             
            

How to specify the arguments types of a method?


             
              class MyFoo:

  #this function take a string and an int. All others arguments types
  #will be rejected even before calling the method.
  @qi.bind(paramsType=(qi.String, qi.Int32))
  def bar(self, arg1, arg2):
    pass

             
            

How to hide that secret internal function?


             
              class MyFoo:

  def bar(self, arg1, arg2):
    pass

  @qi.nobind
  def _privateOfHellBar(self, arg1, arg2):
    pass