From fd0503b08e28591d8b34bd4383d2a3e08943de9f Mon Sep 17 00:00:00 2001 From: Brittany Reynoso Date: Fri, 15 Mar 2024 11:40:53 -0700 Subject: [PATCH] Add FileExistsError and FileNotFoundError to builtins Summary: Add support for missing exception Reviewed By: alexmalyshev Differential Revision: D54907860 fbshipit-source-id: bad2e3824d52853605072085f157d67c49e14f9a --- cinderx/StrictModules/Objects/objects.cpp | 22 +++++++++++++++++++ cinderx/StrictModules/Objects/objects.h | 2 ++ .../comparison_tests/interpreter_test.txt | 12 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/cinderx/StrictModules/Objects/objects.cpp b/cinderx/StrictModules/Objects/objects.cpp index 49a76a86b88..814e6901bd8 100644 --- a/cinderx/StrictModules/Objects/objects.cpp +++ b/cinderx/StrictModules/Objects/objects.cpp @@ -415,6 +415,24 @@ std::shared_ptr LookupErrorType() { return t; } +std::shared_ptr FileExistsErrorType() { + static std::shared_ptr t = makeType( + "FileExistsError", + kBuiltinsModule, + TObjectPtrVec{ExceptionType()}, + TypeType()); + return t; +} + +std::shared_ptr FileNotFoundErrorType() { + static std::shared_ptr t = makeType( + "FileNotFoundError", + kBuiltinsModule, + TObjectPtrVec{ExceptionType()}, + TypeType()); + return t; +} + std::shared_ptr ValueErrorType() { static std::shared_ptr t = makeType( "ValueError", @@ -852,6 +870,8 @@ bool initializeBuiltinsModuleDict() { {"IndexError", IndexErrorType()}, {"LookupError", LookupErrorType()}, {"ValueError", ValueErrorType()}, + {"FileExistsError", FileExistsErrorType()}, + {"FileNotFoundError", FileNotFoundErrorType()}, {"NameError", NameErrorType()}, {"NotImplementedError", NotImplementedErrorType()}, {"StopIteration", StopIterationType()}, @@ -922,6 +942,8 @@ std::shared_ptr getExceptionFromString( {"IndexError", IndexErrorType()}, {"LookupError", LookupErrorType()}, {"ValueError", ValueErrorType()}, + {"FileExistsError", FileExistsErrorType()}, + {"FileNotFoundError", FileNotFoundErrorType()}, {"NameError", NameErrorType()}, {"NotImplementedError", NotImplementedErrorType()}, {"StopIteration", StopIterationType()}, diff --git a/cinderx/StrictModules/Objects/objects.h b/cinderx/StrictModules/Objects/objects.h index 0362cdeabcb..61f649e84b2 100644 --- a/cinderx/StrictModules/Objects/objects.h +++ b/cinderx/StrictModules/Objects/objects.h @@ -88,6 +88,8 @@ std::shared_ptr AttributeErrorType(); std::shared_ptr IndexErrorType(); std::shared_ptr LookupErrorType(); std::shared_ptr ValueErrorType(); +std::shared_ptr FileExistsErrorType(); +std::shared_ptr FileNotFoundErrorType(); std::shared_ptr NameErrorType(); std::shared_ptr NotImplementedErrorType(); std::shared_ptr StopIterationType(); diff --git a/cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt b/cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt index 6b2985432a8..53ce4fa869b 100644 --- a/cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt +++ b/cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt @@ -9999,3 +9999,15 @@ TimeoutError --- --- --- +test_FileExistsError +--- +FileExistsError +--- +--- +--- +test_FileNotFoundError +--- +FileNotFoundError +--- +--- +---