mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-28 10:50:26 +00:00
I used a script to attempt to identify those rules with the following property: changing f-strings to t-strings in the corresponding fixture altered the number of lint errors emitted. In other words, those rules for which f-strings and t-strings are not treated the same in the current implementation. This PR documents the subset of such rules where this is fine and no changes need to be made to the implementation of the rule. Mostly these are the rules where it is relevant that an f-string evaluates to type `str` at runtime whereas t-strings do not. In theory many of these fixtures are not super necessary - it's unlikely t-strings would be used for most of these. However, the internal handling of t-strings is tightly coupled with that of f-strings, and may become even more so as we implement the upcoming changes due to https://github.com/python/cpython/pull/135996 . So I'd like to keep these around as regression tests. Note: The `flake8-bandit` fixtures were already added during the original t-string implementation. | Rule(s) | Reason | | --- | --- | | [`unused-method-argument` (`ARG002`)](https://docs.astral.sh/ruff/rules/unused-method-argument/#unused-method-argument-arg002) | f-strings exempted for msg in `NotImplementedError` not relevant for t-strings | | [`logging-f-string` (`G004`)](https://docs.astral.sh/ruff/rules/logging-f-string/#logging-f-string-g004) | t-strings cannot be used here | | [`f-string-in-get-text-func-call` (`INT001`)](https://docs.astral.sh/ruff/rules/f-string-in-get-text-func-call/#f-string-in-get-text-func-call-int001) | rule justified by eager evaluation of interpolations | | [`flake8-bandit`](https://docs.astral.sh/ruff/rules/#flake8-bandit-s)| rules justified by eager evaluation of interpolations | | [`single-string-slots` (`PLC0205`)](https://docs.astral.sh/ruff/rules/single-string-slots/#single-string-slots-plc0205) | t-strings cannot be slots in general | | [`unnecessary-encode-utf8` (`UP012`)](https://docs.astral.sh/ruff/rules/unnecessary-encode-utf8/#unnecessary-encode-utf8-up012) | cannot encode t-strings | | [`no-self-use` (`PLR6301`)](https://docs.astral.sh/ruff/rules/no-self-use/#no-self-use-plr6301) | f-strings exempted for msg in NotImplementedError not relevant for t-strings | | [`pytest-raises-too-broad` (`PT011`)](https://docs.astral.sh/ruff/rules/pytest-raises-too-broad/) / [`pytest-fail-without-message` (`PT016`)](https://docs.astral.sh/ruff/rules/pytest-fail-without-message/#pytest-fail-without-message-pt016) / [`pytest-warns-too-broad` (`PT030`)](https://docs.astral.sh/ruff/rules/pytest-warns-too-broad/#pytest-warns-too-broad-pt030) | t-strings cannot be empty or used as messages | | [`assert-on-string-literal` (`PLW0129`)](https://docs.astral.sh/ruff/rules/assert-on-string-literal/#assert-on-string-literal-plw0129) | t-strings are not strings and cannot be empty | | [`native-literals` (`UP018`)](https://docs.astral.sh/ruff/rules/native-literals/#native-literals-up018) | t-strings are not native literals |
4 lines
63 B
Python
4 lines
63 B
Python
_(f"{'value'}")
|
|
|
|
# Don't trigger for t-strings
|
|
_(t"{'value'}")
|