
基类:
class Schema(object): ...... def filter(self, obj): filtered = {} for key, value in six.iteritems(obj): if self._filter_func(self.properties, key): filtered[key] = value ...... @staticmethod def _filter_func(properties, key): return key in properties 其中一个重写了该方法的子类:
class PermissiveSchema(Schema): @staticmethod def _filter_func(properties, key): return True 感觉上完全不需要改成 staticmethod
反正最终还是需要传类的属性进去
1 xpresslink 2019-01-10 17:16:09 +08:00 完全没有必要,python 中 staticmethod 很少用到,只是当成类的不同工厂函数时候用一下的情况比较多。 |
2 firejoke OP @xpresslink 我也是觉得完全不必改成 staticmethod, 但源码中大量的工厂和抽象工厂,ABC 基类到处飞, 让我深深怀疑自己没有坐着考虑的深,不敢去质疑作者...... |