validate structured traceback return type return type of CustomTB *should* be a list of strings, but allow single strings or None, which are harmless. This function will *always* return a list of strings, and will raise a Type
(stb)
| 1882 | print('Traceback :', tb) |
| 1883 | |
| 1884 | def validate_stb(stb): |
| 1885 | """validate structured traceback return type |
| 1886 | |
| 1887 | return type of CustomTB *should* be a list of strings, but allow |
| 1888 | single strings or None, which are harmless. |
| 1889 | |
| 1890 | This function will *always* return a list of strings, |
| 1891 | and will raise a TypeError if stb is inappropriate. |
| 1892 | """ |
| 1893 | msg = "CustomTB must return list of strings, not %r" % stb |
| 1894 | if stb is None: |
| 1895 | return [] |
| 1896 | elif isinstance(stb, str): |
| 1897 | return [stb] |
| 1898 | elif not isinstance(stb, list): |
| 1899 | raise TypeError(msg) |
| 1900 | # it's a list |
| 1901 | for line in stb: |
| 1902 | # check every element |
| 1903 | if not isinstance(line, str): |
| 1904 | raise TypeError(msg) |
| 1905 | return stb |
| 1906 | |
| 1907 | if handler is None: |
| 1908 | wrapped = dummy_handler |
nothing calls this directly
no outgoing calls
no test coverage detected