It's a type of Planche
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

56 行
1.4KB

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. class AutoKWArgs(object):
  4. _name = None
  5. _type = None
  6. _size = None
  7. def __init__(self, **kwargs):
  8. """Initialize class setting any items that have a setter with kwargs."""
  9. for key, value in kwargs.items():
  10. if self._has_setter(key):
  11. setattr(self, key, value)
  12. def _has_getter(self, property_key):
  13. """Check if property has getter."""
  14. class_attribute = getattr(type(self), property_key, None)
  15. if isinstance(class_attribute, property):
  16. return class_attribute.fget is not None
  17. return False
  18. def _has_setter(self, property_key):
  19. """Check if property has setter."""
  20. class_attribute = getattr(type(self), property_key, None)
  21. if isinstance(class_attribute, property):
  22. return class_attribute.fset is not None
  23. return False
  24. @property
  25. def name(self):
  26. return self._name
  27. @name.setter
  28. def name(self, value):
  29. if isinstance(value, (str)):
  30. self._name = value
  31. @property
  32. def type(self):
  33. return self._type
  34. @type.setter
  35. def type(self, value):
  36. self._type = value
  37. @property
  38. def size(self):
  39. return self._size
  40. @size.setter
  41. def size(self, value):
  42. if isinstance(value, (int, float)):
  43. self._size = value