Skip to content

Commit 4d613e2

Browse files
committed
SysModuleBuiltins: add audit and audihook builtin stubs
1 parent 66b5ba0 commit 4d613e2

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SysModuleBuiltins.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ public void initialize(Python3Core core) {
466466
builtinConstants.put("ps1", ">>> ");
467467
// continue prompt for interactive shell
468468
builtinConstants.put("ps2", "... ");
469+
// CPython builds for distros report empty strings too, because they are built from
470+
// tarballs, not git
471+
builtinConstants.put("_git", factory.createTuple(new Object[]{"graalpython", "", ""}));
469472

470473
super.initialize(core);
471474

@@ -830,6 +833,33 @@ public static AuditNode create() {
830833
}
831834
}
832835

836+
@Builtin(name = "audit", minNumOfPositionalArgs = 1, takesVarArgs = true, doc = "audit(event, *args)\n" +
837+
"\n" +
838+
"Passes the event to any audit hooks that are attached.")
839+
@GenerateNodeFactory
840+
abstract static class SysAuditNode extends PythonBuiltinNode {
841+
@Specialization
842+
@SuppressWarnings("unused")
843+
Object doAudit(VirtualFrame frame, Object[] args) {
844+
// TODO: Stub audit hooks implementation for PEP 578
845+
return PNone.NONE;
846+
}
847+
}
848+
849+
@Builtin(name = "audithook", minNumOfPositionalArgs = 1, doc = "addaudithook($module, /, hook)\n" +
850+
"--\n" +
851+
"\n" +
852+
"Adds a new audit hook callback.")
853+
@GenerateNodeFactory
854+
abstract static class SysAuditHookNode extends PythonBuiltinNode {
855+
@Specialization
856+
@SuppressWarnings("unused")
857+
Object doAudit(VirtualFrame frame, Object hook) {
858+
// TODO: Stub audit hooks implementation for PEP 578
859+
return PNone.NONE;
860+
}
861+
}
862+
833863
@Builtin(name = "is_finalizing")
834864
@GenerateNodeFactory
835865
public abstract static class IsFinalizingNode extends PythonBuiltinNode {

graalpython/lib-graalpython/sys.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@
3838
# SOFTWARE.
3939

4040

41-
# Stub audit hooks implementation for PEP 578
42-
def audit(str, *args):
43-
pass
44-
45-
def addaudithook(hook):
46-
pass
47-
48-
49-
# CPython builds for distros report empty strings too, because they are built from tarballs, not git
50-
_git = ("graalpython", '', '')
51-
52-
5341
@__graalpython__.builtin
5442
def exit(arg=None):
5543
# see SystemExit_init, tuple of size 1 is unpacked

0 commit comments

Comments
 (0)