From 016e16254a4c888c7fadc3cede77c0456992487b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 9 Oct 2023 18:45:14 +0200 Subject: [PATCH] Update UP038 docs to note that it results in slower code (#7872) See discussion in #7871. I tried to use language similar to the existing performance warnings in the `flake8-use-pathlib` docs, e.g. https://docs.astral.sh/ruff/rules/os-path-abspath/#os-path-abspath-pth100 --- .../src/rules/pyupgrade/rules/use_pep604_isinstance.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index af3e40687a..4849dda185 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -39,9 +39,13 @@ impl CallKind { /// /// ## Why is this bad? /// Since Python 3.10, `isinstance` and `issubclass` can be passed a -/// `|`-separated union of types, which is more concise and consistent +/// `|`-separated union of types, which is consistent /// with the union operator introduced in [PEP 604]. /// +/// Note that this results in slower code. Ignore this rule if the +/// performance of an `isinstance` or `issubclass` check is a +/// concern, e.g., in a hot loop. +/// /// ## Example /// ```python /// isinstance(x, (int, float))