Skip to content

Commit

Permalink
Add UnicodeError, UnicodeDecodeError, UnicodeEncodeError, UnicodeTran…
Browse files Browse the repository at this point in the history
…slateError to builtins

Summary: Add UnicodeError and its child classes (UnicodeDecodeError, UnicodeEncodeError, UnicodeTranslateError) as Strict Module builtin exceptions.

Reviewed By: alexmalyshev

Differential Revision: D55032145

fbshipit-source-id: a60cbdd43144394c34ab84ab8b4f6efb043d4692
  • Loading branch information
Subbarao Garlapati authored and facebook-github-bot committed Mar 20, 2024
1 parent 04cce4f commit bf4d87a
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cinderx/StrictModules/Objects/objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,42 @@ std::shared_ptr<StrictType> ConnectionResetErrorType() {
return t;
}

std::shared_ptr<StrictType> UnicodeErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"UnicodeError",
kBuiltinsModule,
TObjectPtrVec{ValueErrorType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> UnicodeDecodeErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"UnicodeDecodeError",
kBuiltinsModule,
TObjectPtrVec{UnicodeErrorType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> UnicodeEncodeErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"UnicodeEncodeError",
kBuiltinsModule,
TObjectPtrVec{UnicodeErrorType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> UnicodeTranslateErrorType() {
static std::shared_ptr<StrictType> t = makeType<StrictExceptionType>(
"UnicodeTranslateError",
kBuiltinsModule,
TObjectPtrVec{UnicodeErrorType()},
TypeType());
return t;
}

std::shared_ptr<StrictType> LazyObjectType() {
static std::shared_ptr<StrictType> t = makeType<StrictLazyObjectType>(
"<lazy type>", kBuiltinsModule, TObjectPtrVec{}, TypeType());
Expand Down Expand Up @@ -987,6 +1023,10 @@ bool initializeBuiltinsModuleDict() {
{"TimeoutError", TimeoutErrorType()},
{"True", StrictTrue()},
{"TypeError", TypeErrorType()},
{"UnicodeDecodeError", UnicodeDecodeErrorType()},
{"UnicodeEncodeError", UnicodeEncodeErrorType()},
{"UnicodeError", UnicodeErrorType()},
{"UnicodeTranslateError", UnicodeTranslateErrorType()},
{"ValueError", ValueErrorType()},
{"ZeroDivisionError", DivisionByZeroType()},
{"__builtins__", DunderBuiltins()},
Expand Down Expand Up @@ -1083,6 +1123,10 @@ std::shared_ptr<StrictType> getExceptionFromString(
{"SyntaxError", SyntaxErrorType()},
{"TimeoutError", TimeoutErrorType()},
{"TypeError", TypeErrorType()},
{"UnicodeDecodeError", UnicodeDecodeErrorType()},
{"UnicodeEncodeError", UnicodeEncodeErrorType()},
{"UnicodeError", UnicodeErrorType()},
{"UnicodeTranslateError", UnicodeTranslateErrorType()},
{"ValueError", ValueErrorType()},
{"ZeroDivisionError", DivisionByZeroType()},
});
Expand Down
24 changes: 24 additions & 0 deletions cinderx/StrictModules/Tests/comparison_tests/interpreter_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10089,3 +10089,27 @@ ConnectionResetError
---
---
---
test_UnicodeError
---
UnicodeError
---
---
---
test_UnicodeDecodeError
---
UnicodeDecodeError
---
---
---
test_UnicodeEncodeError
---
UnicodeEncodeError
---
---
---
test_UnicodeTranslateError
---
UnicodeTranslateError
---
---
---

0 comments on commit bf4d87a

Please sign in to comment.