Handle TOML config values with strict type validation and no coercion. In TOML mode, values already have native types from TOML parsing. We validate types match expectations exactly, including list items.
(
self,
name: str,
canonical_name: str,
type: str,
value: object,
default: Any,
)
| 1818 | return self._getini_unknown_type(name, type, value) |
| 1819 | |
| 1820 | def _getini_toml( |
| 1821 | self, |
| 1822 | name: str, |
| 1823 | canonical_name: str, |
| 1824 | type: str, |
| 1825 | value: object, |
| 1826 | default: Any, |
| 1827 | ): |
| 1828 | """Handle TOML config values with strict type validation and no coercion. |
| 1829 | |
| 1830 | In TOML mode, values already have native types from TOML parsing. |
| 1831 | We validate types match expectations exactly, including list items. |
| 1832 | """ |
| 1833 | value_type = builtins.type(value).__name__ |
| 1834 | if type == "paths": |
| 1835 | # Expect a list of strings. |
| 1836 | if not isinstance(value, list): |
| 1837 | raise TypeError( |
| 1838 | f"{self.inipath}: config option '{name}' expects a list for type 'paths', " |
| 1839 | f"got {value_type}: {value!r}" |
| 1840 | ) |
| 1841 | for i, item in enumerate(value): |
| 1842 | if not isinstance(item, str): |
| 1843 | item_type = builtins.type(item).__name__ |
| 1844 | raise TypeError( |
| 1845 | f"{self.inipath}: config option '{name}' expects a list of strings, " |
| 1846 | f"but item at index {i} is {item_type}: {item!r}" |
| 1847 | ) |
| 1848 | dp = ( |
| 1849 | self.inipath.parent |
| 1850 | if self.inipath is not None |
| 1851 | else self.invocation_params.dir |
| 1852 | ) |
| 1853 | return [dp / x for x in value] |
| 1854 | elif type in {"args", "linelist"}: |
| 1855 | # Expect a list of strings. |
| 1856 | if not isinstance(value, list): |
| 1857 | raise TypeError( |
| 1858 | f"{self.inipath}: config option '{name}' expects a list for type '{type}', " |
| 1859 | f"got {value_type}: {value!r}" |
| 1860 | ) |
| 1861 | for i, item in enumerate(value): |
| 1862 | if not isinstance(item, str): |
| 1863 | item_type = builtins.type(item).__name__ |
| 1864 | raise TypeError( |
| 1865 | f"{self.inipath}: config option '{name}' expects a list of strings, " |
| 1866 | f"but item at index {i} is {item_type}: {item!r}" |
| 1867 | ) |
| 1868 | return list(value) |
| 1869 | elif type == "bool": |
| 1870 | # Expect a boolean. |
| 1871 | if not isinstance(value, bool): |
| 1872 | raise TypeError( |
| 1873 | f"{self.inipath}: config option '{name}' expects a bool, " |
| 1874 | f"got {value_type}: {value!r}" |
| 1875 | ) |
| 1876 | return value |
| 1877 | elif type == "int": |
no test coverage detected