Possibly cleaner would be to write it like here:

https://github.com/fizyk/pyramid_fullauth/blob/master/pyramid_fullauth/__init__.py#L46