Whole file

didix21/mdutils

The author described this change as Fix #42 Default table's text_align should be '---'. It counts as a record because the check below fails on the code as it stood at b9c958631 and passes on c11571ea1, with nothing else changed between the two runs.

Fix saved2020-09-12
Sharing licenceMIT · LICENSE.txt
Change size+12 7

What the code was meant to do, written into the code itself as a save note

Fix #42 Default table's text_align should be '---'

The change

55 # This file is part of mdutils. https://github.com/didix21/mdutils
66 #
77 # MIT License: (C) 2020 Dídac Coll
8+from typing import Optional
89
910
1011 class Table:
1415 self.columns = 0
1516
1617 @staticmethod
17- def _align(columns, text_align):
18+ def _align(columns, text_align: Optional[str] = None) -> str:
1819 """ This private method it's in charge of aligning text of a table.
1920
2021 - notes: more information about `text_align`
4445
4546 column_align_string = '|' + ''.join([' ---: |' for _ in range(columns)])
4647
48+ elif text_align is None:
49+
50+ column_align_string = '|' + ''.join([' --- |' for _ in range(columns)])
51+
4752 return column_align_string
4853
49- def create_table(self, columns, rows, text, text_align='center'):
54+ def create_table(self, columns: int, rows: int, text: [str], text_align: Optional[str] = None):
5055 """This method takes a list of strings and creates a table.
5156
5257 Using arguments ``columns`` and ``rows`` allows to create a table of *n* columns and *m* rows.
8388 column_align_string = self._align(columns, text_align)
8489 index = 0
8590 if columns * rows == len(text):
86- if text_align.lower() in ('right', 'center', 'left'):
87- for r in range(rows + 1):
88- if r == 1:
91+ if text_align is None or text_align.lower() in ('right', 'center', 'left'):
92+ for row in range(rows + 1):
93+ if row == 1:
8994 table += column_align_string # Row align, Example: '| :---: | :---: | ... | \n'
9095 else:
9196 table += '|'
92- for c in range(columns):
97+ for _ in range(columns):
9398 table += text[index] + '|'
9499 index += 1
95100
98103 return table
99104
100105 else:
101- raise ValueError("text_align's expected value: 'right', 'center' or 'left', but text_align = "
106+ raise ValueError("text_align's expected value: 'right', 'center', 'left' or None , but text_align = "
102107 + text_align.lower())
103108 else:
104109 raise ValueError("columns * rows is not equal to text length")

The check that tells the two apart

failpass·tests/test_tools/test_table.py::TestTable::test_create_default_table

Check file tests/test_tools/test_table.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itb9c95863140901d29ffc9c2518fcdb27d7eb054f
Broken version dated2020-09-12
Modulemdutils.tools.Table
Units changedTable
Fingerprint831d7a145ac62154
Checked2026-08-18 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in didix21/mdutils