Spec.format: error on old style format strings (#41934)
This commit is contained in:
		| @@ -213,6 +213,19 @@ def __call__(self, match): | |||||||
|     return clr.colorize(re.sub(_SEPARATORS, insert_color(), str(spec)) + "@.") |     return clr.colorize(re.sub(_SEPARATORS, insert_color(), str(spec)) + "@.") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | OLD_STYLE_FMT_RE = re.compile(r"\${[A-Z]+}") | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def ensure_modern_format_string(fmt: str) -> None: | ||||||
|  |     """Ensure that the format string does not contain old ${...} syntax.""" | ||||||
|  |     result = OLD_STYLE_FMT_RE.search(fmt) | ||||||
|  |     if result: | ||||||
|  |         raise SpecFormatStringError( | ||||||
|  |             f"Format string `{fmt}` contains old syntax `{result.group(0)}`. " | ||||||
|  |             "This is no longer supported." | ||||||
|  |         ) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| @lang.lazy_lexicographic_ordering | @lang.lazy_lexicographic_ordering | ||||||
| class ArchSpec: | class ArchSpec: | ||||||
|     """Aggregate the target platform, the operating system and the target microarchitecture.""" |     """Aggregate the target platform, the operating system and the target microarchitecture.""" | ||||||
| @@ -4362,6 +4375,7 @@ def format(self, format_string=DEFAULT_FORMAT, **kwargs): | |||||||
|                 that accepts a string and returns another one |                 that accepts a string and returns another one | ||||||
| 
 | 
 | ||||||
|         """ |         """ | ||||||
|  |         ensure_modern_format_string(format_string) | ||||||
|         color = kwargs.get("color", False) |         color = kwargs.get("color", False) | ||||||
|         transform = kwargs.get("transform", {}) |         transform = kwargs.get("transform", {}) | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -1528,3 +1528,9 @@ def test_edge_equality_does_not_depend_on_virtual_order(): | |||||||
|     assert edge1 == edge2 |     assert edge1 == edge2 | ||||||
|     assert tuple(sorted(edge1.virtuals)) == edge1.virtuals |     assert tuple(sorted(edge1.virtuals)) == edge1.virtuals | ||||||
|     assert tuple(sorted(edge2.virtuals)) == edge1.virtuals |     assert tuple(sorted(edge2.virtuals)) == edge1.virtuals | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def test_old_format_strings_trigger_error(default_mock_concretization): | ||||||
|  |     s = Spec("a").concretized() | ||||||
|  |     with pytest.raises(SpecFormatStringError): | ||||||
|  |         s.format("${PACKAGE}-${VERSION}-${HASH}") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Harmen Stoppels
					Harmen Stoppels