-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathImportError.cpp
More file actions
85 lines (69 loc) · 2.02 KB
/
Copy pathImportError.cpp
File metadata and controls
85 lines (69 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "ImportError.hpp"
#include "PyString.hpp"
#include "types/api.hpp"
#include "types/builtin.hpp"
namespace py {
ImportError::ImportError(PyType *type) : ImportError(type->underlying_type(), nullptr) {}
ImportError::ImportError(PyType *type, PyTuple *args) : ImportError(type->underlying_type(), args)
{}
ImportError::ImportError(TypePrototype &type, PyTuple *args) : Exception(type, args) {}
ImportError::ImportError(PyTuple *args)
: ImportError(types::BuiltinTypes::the().import_error(), args)
{}
PyResult<PyObject *> ImportError::__new__(const PyType *type, PyTuple *args, PyDict *kwargs)
{
ASSERT(type == types::import_error());
if (auto result = ImportError::create(args)) {
if (kwargs) {
if (auto it = kwargs->map().find(String{ "name" }); it != kwargs->map().end()) {
result->m_name = PyObject::from(it->second).unwrap();
}
}
return Ok(static_cast<PyObject *>(result));
} else {
TODO();
}
}
PyResult<int32_t> ImportError::__init__(PyTuple *args, PyDict *kwargs)
{
m_args = args;
if (kwargs) {
if (auto it = kwargs->map().find(String{ "name" }); it != kwargs->map().end()) {
m_name = PyObject::from(it->second).unwrap();
}
}
return Ok(1);
}
PyType *ImportError::class_type()
{
ASSERT(types::import_error());
return types::import_error();
}
PyType *ImportError::static_type() const
{
ASSERT(types::import_error());
return types::import_error();
}
void ImportError::visit_graph(Visitor &visitor)
{
Exception::visit_graph(visitor);
if (m_name) visitor.visit(*m_name);
}
namespace {
std::once_flag import_error_flag;
std::unique_ptr<TypePrototype> register_import_error()
{
return std::move(klass<ImportError>("ImportError", Exception::class_type())
.attr("name", &ImportError::m_name)
.type);
}
}// namespace
std::function<std::unique_ptr<TypePrototype>()> ImportError::type_factory()
{
return []() {
static std::unique_ptr<TypePrototype> type = nullptr;
std::call_once(import_error_flag, []() { type = register_import_error(); });
return std::move(type);
};
}
}// namespace py