Ask Your Question

what the code "return cls()" meaning

asked 2012-03-13 08:48:56 -0500

oliver-huang gravatar image

I am a newcomer of openstack and python. When I read the code in file nova-2011.3\nova\api\

I found these lines

class APIRouter(base_wsgi.Router): """ Routes requests on the OpenStack API to the appropriate controller and method. """

def factory(cls, global_config, **local_config):
    """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one"""
    return cls()

My question is: what the code "return cls()" means in the factory() class method? where to find the factory() method body?

Please help me, thx.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2012-03-22 19:57:43 -0500

Since factory is marked as a @classmethod, the first argument is the class, APIRouter. So, "return cls()" is effectively the same thing as "return APIRouter()".

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2012-03-13 08:48:56 -0500

Seen: 2,940 times

Last updated: Mar 22 '12