static_var n'a pas vraiment de raison d'être dans affichage.py

This commit is contained in:
Pierre-Elliott Bécue 2015-03-22 02:12:27 +01:00
parent 394531a537
commit 3f1b7401ca
2 changed files with 23 additions and 21 deletions

20
cranslib/decorators.py Normal file
View file

@ -0,0 +1,20 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import functools
def static_var(*couples):
"""Decorator setting static variable
to a function.
"""
# Using setattr magic, we set static
# variable on function. This avoid
# computing stuff again.
def decorate(fun):
functools.wraps(fun)
for (name, val) in couples:
setattr(fun, name, val)
return fun
return decorate