mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-27 15:14:31 +00:00
Add an accessor to PyCallable that allows one to determine the count of arguments that a Python function allows, and whether varargs/kwargs are also accepted by the same function
llvm-svn: 218812
This commit is contained in:
1 parent
b4b09c7a6c
commit
d1fd3ce42e
1 file changed
+26
-1
@@ -105,7 +105,32 @@ FindSessionDictionary(const char *session_dictionary_name)
|
||||
class PyCallable
|
||||
{
|
||||
public:
|
||||
|
||||
struct argc {
|
||||
size_t num_args;
|
||||
bool varargs : 1;
|
||||
bool kwargs : 1;
|
||||
};
|
||||
|
||||
argc
|
||||
GetNumArguments ()
|
||||
{
|
||||
if (m_callable && PyFunction_Check(m_callable))
|
||||
{
|
||||
PyCodeObject* code = (PyCodeObject*)PyFunction_GET_CODE(m_callable);
|
||||
if (code)
|
||||
{
|
||||
size_t args = code->co_argcount;
|
||||
bool va=false,kw=false;
|
||||
if ((code->co_flags & 4) == 4)
|
||||
va = true;
|
||||
if ((code->co_flags & 8) == 8)
|
||||
kw = true;
|
||||
return {args,va,kw};
|
||||
}
|
||||
}
|
||||
return {SIZE_MAX,false,false};
|
||||
}
|
||||
|
||||
operator
|
||||
bool ()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user