Ask Your Question

what the code "return cls()" meaning

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

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 -0600

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


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

Seen: 1,705 times

Last updated: Mar 22 '12