summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJames Addison <james@reciperadar.com>2023-04-10 15:40:38 -0400
committerFederico Caselli <cfederico87@gmail.com>2023-04-12 22:36:39 +0200
commitd3f869bb3159d18669fb6f00cbe514307118eea7 (patch)
tree32b83d276b3eaf779dcea37aa1c59e0b0da5e596 /tools
parent33a9947686a7c8bb3becd6169ec7abe84cf2c7e6 (diff)
downloadalembic-d3f869bb3159d18669fb6f00cbe514307118eea7.tar.gz
tooling: write_pyi.py: filter usage of raw-strings (rstrings)
### Description While reading the diff between [`rel_1_10_2...rel_1_10_3`](https://github.com/sqlalchemy/alembic/compare/rel_1_10_2...rel_1_10_3), the introduction of r-strings drew my attention, and that resulted in some [discussion on the relevant commit](https://github.com/sqlalchemy/alembic/commit/bc0c305b7c2cc0401e250fcd6a725aacecdd6e33). This changeset filters the production of r-strings during stub-generation to cases where docstrings contain escape (backslash, `\`) characters. I'll admit that I didn't realize until today that these stubs are primarily for typechecking. Since that's the case, I have doubts about whether the change is worthwhile (consistency and simplicity -- using r-strings for all docstrings in the stubs -- even if it's redundant, seems fine to me). ### Checklist This pull request is: - [x] A documentation / typographical error fix - [x] A short code fix - Relates to discussion at https://github.com/sqlalchemy/alembic/commit/bc0c305b7c2cc0401e250fcd6a725aacecdd6e33 Closes: #1218 Pull-request: https://github.com/sqlalchemy/alembic/pull/1218 Pull-request-sha: 352ab8829525435f78838687e12156a3fa3a3d86 Closes: #1219 Pull-request: https://github.com/sqlalchemy/alembic/pull/1219 Change-Id: I2808a592681dabc093d538f589e673fcc5e05822
Diffstat (limited to 'tools')
-rw-r--r--tools/write_pyi.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/tools/write_pyi.py b/tools/write_pyi.py
index fcf9d36..4fbf366 100644
--- a/tools/write_pyi.py
+++ b/tools/write_pyi.py
@@ -218,7 +218,8 @@ def _generate_stub_for_meth(
fn_doc = base_method.__doc__ if base_method else fn.__doc__
has_docs = gen_docs and fn_doc is not None
- docs = 'r"""' + f"{fn_doc}" + '"""' if has_docs else ""
+ string_prefix = "r" if chr(92) in fn_doc else ""
+ docs = f'{string_prefix}"""' + f"{fn_doc}" + '"""' if has_docs else ""
func_text = textwrap.dedent(
f"""