Skip to content

Commit

Permalink
Add FileExistsError and FileNotFoundError to builtins
Browse files Browse the repository at this point in the history
Summary: Add support for missing exception

Reviewed By: alexmalyshev

Differential Revision: D54907860

fbshipit-source-id: bad2e3824d52853605072085f157d67c49e14f9a
  • Loading branch information
Brittany Reynoso authored and facebook-github-bot committed Mar 15, 2024
1 parent c88dddd commit fd0503b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cinderx/StrictModules/Objects/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,24 @@ std::shared_ptr<StrictType> LookupErrorType() {
return t;
}

std::shared_ptr<StrictType> FileExistsErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"FileExistsError",
kBuiltinsModule,
TObjectPtrVec{ExceptionType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> FileNotFoundErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"FileNotFoundError",
kBuiltinsModule,
TObjectPtrVec{ExceptionType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> ValueErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"ValueError",
Expand Down Expand Up @@ -852,6 +870,8 @@ bool initializeBuiltinsModuleDict() {
{"IndexError", IndexErrorType()},
{"LookupError", LookupErrorType()},
{"ValueError", ValueErrorType()},
{"FileExistsError", FileExistsErrorType()},
{"FileNotFoundError", FileNotFoundErrorType()},
{"NameError", NameErrorType()},
{"NotImplementedError", NotImplementedErrorType()},
{"StopIteration", StopIterationType()},
Expand Down Expand Up @@ -922,6 +942,8 @@ std::shared_ptr<StrictType> getExceptionFromString(
{"IndexError", IndexErrorType()},
{"LookupError", LookupErrorType()},
{"ValueError", ValueErrorType()},
{"FileExistsError", FileExistsErrorType()},
{"FileNotFoundError", FileNotFoundErrorType()},
{"NameError", NameErrorType()},
{"NotImplementedError", NotImplementedErrorType()},
{"StopIteration", StopIterationType()},
Expand Down
2 changes: 2 additions & 0 deletions cinderx/StrictModules/Objects/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ std::shared_ptr<StrictType> AttributeErrorType();
std::shared_ptr<StrictType> IndexErrorType();
std::shared_ptr<StrictType> LookupErrorType();
std::shared_ptr<StrictType> ValueErrorType();
std::shared_ptr<StrictType> FileExistsErrorType();
std::shared_ptr<StrictType> FileNotFoundErrorType();
std::shared_ptr<StrictType> NameErrorType();
std::shared_ptr<StrictType> NotImplementedErrorType();
std::shared_ptr<StrictType> StopIterationType();
Expand Down
12 changes: 12 additions & 0 deletions cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9999,3 +9999,15 @@ TimeoutError
---
---
---
test_FileExistsError
---
FileExistsError
---
---
---
test_FileNotFoundError
---
FileNotFoundError
---
---
---

0 comments on commit fd0503b

Please sign in to comment.