]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
♻ Simplify internal RegEx in `fastapi/utils.py` (#5057)
authorpylounge <78209508+pylounge@users.noreply.github.com>
Fri, 26 Aug 2022 13:46:22 +0000 (16:46 +0300)
committerGitHub <noreply@github.com>
Fri, 26 Aug 2022 13:46:22 +0000 (15:46 +0200)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
fastapi/utils.py

index b7da3e484240c04fcffbcf47221664c1a9b5c91f..0ced0125223a4e3dd00aacfa5f1c8e2b988dee1e 100644 (file)
@@ -140,14 +140,14 @@ def generate_operation_id_for_path(
         stacklevel=2,
     )
     operation_id = name + path
-    operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
+    operation_id = re.sub(r"\W", "_", operation_id)
     operation_id = operation_id + "_" + method.lower()
     return operation_id
 
 
 def generate_unique_id(route: "APIRoute") -> str:
     operation_id = route.name + route.path_format
-    operation_id = re.sub("[^0-9a-zA-Z_]", "_", operation_id)
+    operation_id = re.sub(r"\W", "_", operation_id)
     assert route.methods
     operation_id = operation_id + "_" + list(route.methods)[0].lower()
     return operation_id