staticmethod makes my brain hurt

alex23 wuwei23 at gmail.com
Thu Nov 17 21:31:04 EST 2011


On Nov 17, 1:24 pm, Ethan Furman <et... at stoneleaf.us> wrote:
> If you do need to sometimes call it from a method then still leave off
> the '@staticmethod', and give 'self' a default of 'None':
>
>      def _get_next_id(self=None):
>        [blah, blah, blah]
>        return id
>
>      user_id = IntField(required=True, default=_get_next_id)

And if the OP needs it to be a staticmethod as well, he can just wrap
the nested function:

      gen_next_id = staticmethod(_gen_next_id)

I think I like this approach best. I'm annoyed that I forgot functions
declared in a class scope were callable within the definition :)




More information about the Python-list mailing list