| Total Complexity | 6 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | """ |
||
| 12 | class Writer: |
||
|
1 ignored issue
–
show
|
|||
| 13 | """ |
||
| 14 | Abstract parent class for writing rows to a destination. |
||
| 15 | """ |
||
| 16 | |||
| 17 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 18 | def __init__(self): |
||
| 19 | """ |
||
| 20 | Object constructor. |
||
| 21 | """ |
||
| 22 | |||
| 23 | self._fields = [] |
||
| 24 | """ |
||
| 25 | The fields (or columns) that must be written to the destination. |
||
| 26 | |||
| 27 | :type list[str]: |
||
| 28 | """ |
||
| 29 | |||
| 30 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 31 | @property |
||
| 32 | def fields(self): |
||
| 33 | """ |
||
| 34 | Getter for fields. |
||
| 35 | |||
| 36 | :rtype: list[str] |
||
| 37 | """ |
||
| 38 | return copy.copy(self._fields) |
||
| 39 | |||
| 40 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 41 | @fields.setter |
||
| 42 | def fields(self, fields): |
||
| 43 | """ |
||
| 44 | Setter for fields. |
||
| 45 | |||
| 46 | :param list[str] fields: The fields (or columns) that must be written to the destination. |
||
| 47 | """ |
||
| 48 | self._fields = fields |
||
| 49 | |||
| 50 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 51 | @abc.abstractmethod |
||
| 52 | def writerow(self, row): |
||
| 53 | """ |
||
| 54 | Writes a row to the destination. |
||
| 55 | |||
| 56 | :param dict[str,T] row: The row. |
||
| 57 | |||
| 58 | :rtype: None |
||
| 59 | """ |
||
| 60 | raise NotImplementedError() |
||
| 61 | |||
| 62 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 63 | def __enter__(self): |
||
| 64 | raise NotImplementedError() |
||
| 65 | |||
| 66 | # ------------------------------------------------------------------------------------------------------------------ |
||
| 67 | def __exit__(self, exc_type, exc_value, traceback): |
||
| 68 | raise NotImplementedError() |
||
| 69 | |||
| 71 |
Abstract classes which are used only once can usually be inlined into the class which already uses this abstract class.