Skip to content

Commit 371f8f8

Browse files
Merge pull request RustPython#298 from idbentley/alphebetize_exceptions
Alphebetize exception related code
2 parents 0f87d15 + f2db23b commit 371f8f8

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

vm/src/exceptions.rs

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ fn exception_str(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
8181

8282
#[derive(Debug)]
8383
pub struct ExceptionZoo {
84-
pub base_exception_type: PyObjectRef,
85-
pub exception_type: PyObjectRef,
86-
pub syntax_error: PyObjectRef,
8784
pub assertion_error: PyObjectRef,
8885
pub attribute_error: PyObjectRef,
86+
pub base_exception_type: PyObjectRef,
87+
pub exception_type: PyObjectRef,
88+
pub file_not_found_error: PyObjectRef,
89+
pub import_error: PyObjectRef,
8990
pub index_error: PyObjectRef,
9091
pub key_error: PyObjectRef,
92+
pub module_not_found_error: PyObjectRef,
9193
pub name_error: PyObjectRef,
92-
pub runtime_error: PyObjectRef,
9394
pub not_implemented_error: PyObjectRef,
95+
pub permission_error: PyObjectRef,
96+
pub runtime_error: PyObjectRef,
9497
pub stop_iteration: PyObjectRef,
98+
pub syntax_error: PyObjectRef,
9599
pub type_error: PyObjectRef,
96100
pub value_error: PyObjectRef,
97-
pub import_error: PyObjectRef,
98-
pub module_not_found_error: PyObjectRef,
99-
pub file_not_found_error: PyObjectRef,
100-
pub permission_error: PyObjectRef,
101101
}
102102

103103
impl ExceptionZoo {
@@ -106,11 +106,13 @@ impl ExceptionZoo {
106106
object_type: &PyObjectRef,
107107
dict_type: &PyObjectRef,
108108
) -> Self {
109+
// Sorted By Hierarchy then alphabetized.
110+
109111
let base_exception_type =
110112
create_type("BaseException", &type_type, &object_type, &dict_type);
111113

112114
let exception_type = create_type("Exception", &type_type, &base_exception_type, &dict_type);
113-
let syntax_error = create_type("SyntaxError", &type_type, &exception_type, &dict_type);
115+
114116
let assertion_error =
115117
create_type("AssertionError", &type_type, &exception_type, &dict_type);
116118
let attribute_error = create_type(
@@ -119,6 +121,7 @@ impl ExceptionZoo {
119121
&exception_type.clone(),
120122
&dict_type,
121123
);
124+
let import_error = create_type("ImportError", &type_type, &exception_type, &dict_type);
122125
let index_error = create_type(
123126
"IndexError",
124127
&type_type,
@@ -128,41 +131,42 @@ impl ExceptionZoo {
128131
let key_error = create_type("KeyError", &type_type, &exception_type.clone(), &dict_type);
129132
let name_error = create_type("NameError", &type_type, &exception_type.clone(), &dict_type);
130133
let runtime_error = create_type("RuntimeError", &type_type, &exception_type, &dict_type);
134+
let stop_iteration = create_type("StopIteration", &type_type, &exception_type, &dict_type);
135+
let syntax_error = create_type("SyntaxError", &type_type, &exception_type, &dict_type);
136+
let type_error = create_type("TypeError", &type_type, &exception_type, &dict_type);
137+
let value_error = create_type("ValueError", &type_type, &exception_type, &dict_type);
138+
139+
let file_not_found_error =
140+
create_type("FileNotFoundError", &type_type, &import_error, &dict_type);
141+
let module_not_found_error =
142+
create_type("ModuleNotFoundError", &type_type, &import_error, &dict_type);
131143
let not_implemented_error = create_type(
132144
"NotImplementedError",
133145
&type_type,
134146
&runtime_error,
135147
&dict_type,
136148
);
137-
let stop_iteration = create_type("StopIteration", &type_type, &exception_type, &dict_type);
138-
let type_error = create_type("TypeError", &type_type, &exception_type, &dict_type);
139-
let value_error = create_type("ValueError", &type_type, &exception_type, &dict_type);
140-
let import_error = create_type("ImportError", &type_type, &exception_type, &dict_type);
141-
let module_not_found_error =
142-
create_type("ModuleNotFoundError", &type_type, &import_error, &dict_type);
143-
let file_not_found_error =
144-
create_type("FileNotFoundError", &type_type, &import_error, &dict_type);
145149
let permission_error =
146150
create_type("PermissionError", &type_type, &import_error, &dict_type);
147151

148152
ExceptionZoo {
149-
base_exception_type: base_exception_type,
150-
exception_type: exception_type,
151-
syntax_error: syntax_error,
152153
assertion_error: assertion_error,
153154
attribute_error: attribute_error,
155+
base_exception_type: base_exception_type,
156+
exception_type: exception_type,
157+
file_not_found_error: file_not_found_error,
158+
import_error: import_error,
154159
index_error: index_error,
155160
key_error: key_error,
161+
module_not_found_error: module_not_found_error,
156162
name_error: name_error,
157-
runtime_error: runtime_error,
158163
not_implemented_error: not_implemented_error,
164+
permission_error: permission_error,
165+
runtime_error: runtime_error,
159166
stop_iteration: stop_iteration,
167+
syntax_error: syntax_error,
160168
type_error: type_error,
161169
value_error: value_error,
162-
import_error: import_error,
163-
module_not_found_error: module_not_found_error,
164-
file_not_found_error: file_not_found_error,
165-
permission_error: permission_error,
166170
}
167171
}
168172
}

0 commit comments

Comments
 (0)