From 3b2ff36abb22f4d681d6c55271d0d1952945bc9c Mon Sep 17 00:00:00 2001 From: David Pichardie Date: Wed, 23 Oct 2024 08:38:08 -0700 Subject: [PATCH] [inferpython] bugfix the qualified name given to a module Summary: removing the / in the path. It helps with the Textual generation. Reviewed By: geralt-encore Differential Revision: D64814008 Privacy Context Container: L1208441 fbshipit-source-id: 78581d42cef88e1f1e8514e83d4b353f9f5fdcbe --- infer/src/python/PyIR.ml | 2 +- infer/src/python/unit/PyIRTestImport.ml | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/infer/src/python/PyIR.ml b/infer/src/python/PyIR.ml index 3d2550d4a9..44d94f82de 100644 --- a/infer/src/python/PyIR.ml +++ b/infer/src/python/PyIR.ml @@ -2606,7 +2606,7 @@ let file_path {FFI.Code.co_filename} = String.sub co_filename ~pos:2 ~len:(sz - 2) else co_filename in - Stdlib.Filename.remove_extension file_path + Stdlib.Filename.remove_extension file_path |> String.substr_replace_all ~pattern:"/" ~with_:"::" let mk ~debug code = diff --git a/infer/src/python/unit/PyIRTestImport.ml b/infer/src/python/unit/PyIRTestImport.ml index fd5c5267b4..f624e2c02a 100644 --- a/infer/src/python/unit/PyIRTestImport.ml +++ b/infer/src/python/unit/PyIRTestImport.ml @@ -265,7 +265,7 @@ path.X() PyIR.test ~filename:"some/long/path/dummy.py" source ; [%expect {| - module some/long/path/dummy: + module some::long::path::dummy: function toplevel(): b0: @@ -292,6 +292,20 @@ path.X() return None |}] +let%expect_test _ = + let source = {| +pass +|} in + PyIR.test ~filename:"./dir1/dir2/script.py" source ; + [%expect + {| + module dir1::dir2::script: + + function toplevel(): + b0: + return None |}] + + let%expect_test _ = let source = {|