Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
(import "ci/python-gate.libsonnet") +
(import "ci/python-bench.libsonnet") +
{
overlay: "30def35dbfc43256d57ad3b9b981d92718728e2a",
overlay: "26571215e27b3c415afb8119d38a0418c14b29c9",
specVersion: "8",
// Until buildbot issues around CI tiers are resolved, we cannot use them
// tierConfig: self.tierConfig,
Expand Down
16 changes: 16 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ def test_from_list():
assert list(b) == ints


def test_bytearray_from_none():
assert_raises(TypeError, bytes, None)
assert_raises(TypeError, bytearray, None)


def test_bytes_with_encoding_does_not_call_dunder_bytes():
class BytesLike:
def __bytes__(self):
return b"bytes"

assert bytes(BytesLike()) == b"bytes"
assert_raises(TypeError, bytes, BytesLike(), None)
assert_raises(TypeError, bytes, encoding="utf-8")
assert_raises(TypeError, bytes, errors="strict")


def test_from_ssize():
assert bytes(0) == b''
assert bytes(1) == b'\x00'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ def set_dict_attr():
assert_raises(AttributeError, set_dict_attr)


def test_lookup_single_underscore_attr():
class MyClass:
pass

assert_raises(AttributeError, lambda: MyClass()._)


def test_set_dict_attr():
class MyClass(object):
def __init__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def m(self): return ["B"] + self.my_super.m()
assert B().m() == ["B", "A"]


def test_super_requires_type_arg():
try:
super([])
except TypeError:
pass
else:
assert False


def test_super_subclass_descr_get_invokes_subclass_type():
class MySuper(super):
news = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2025, Oracle and/or its affiliates.
* Copyright (c) 2020, 2026, Oracle and/or its affiliates.
* Copyright (c) 2014, Regents of the University of California
*
* All rights reserved.
Expand Down Expand Up @@ -164,20 +164,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
return ByteArrayBuiltinsClinicProviders.InitNodeClinicProviderGen.INSTANCE;
}

@Specialization(guards = "!isNone(source)")
@Specialization
static PNone doInit(VirtualFrame frame, PByteArray self, Object source, Object encoding, Object errors,
@Bind Node inliningTarget,
@Cached BytesNodes.BytesInitNode toBytesNode) {
self.setSequenceStorage(new ByteSequenceStorage(toBytesNode.execute(frame, inliningTarget, source, encoding, errors)));
return PNone.NONE;
}

@Specialization(guards = "isNone(self)")
static PNone doInit(@SuppressWarnings("unused") PByteArray self, Object source, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
@Bind Node inliningTarget) {
throw PRaiseNode.raiseStatic(inliningTarget, TypeError, ErrorMessages.CANNOT_CONVERT_P_OBJ_TO_S, source, "bytearray");
}

@Specialization(guards = "!isBytes(self)")
static PNone doInit(Object self, @SuppressWarnings("unused") Object source, @SuppressWarnings("unused") Object encoding, @SuppressWarnings("unused") Object errors,
@Bind Node inliningTarget) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ protected ArgumentClinicProvider getArgumentClinic() {
}

@SuppressWarnings("unused")
@Specialization(guards = "isNoValue(source)")
@Specialization(guards = {"isNoValue(source)", "isNoValue(encoding)", "isNoValue(errors)"})
static Object doEmpty(Object cls, PNone source, PNone encoding, PNone errors,
@Bind Node inliningTarget,
@Exclusive @Cached CreateBytes createBytes) {
return createBytes.execute(inliningTarget, cls, PythonUtils.EMPTY_BYTE_ARRAY);
}

@Specialization(guards = "!isNoValue(source)")
@Specialization(guards = {"!isNoValue(source)", "isNoValue(encoding)", "isNoValue(errors)"})
static Object doCallBytes(VirtualFrame frame, Object cls, Object source, PNone encoding, PNone errors,
@Bind Node inliningTarget,
@Cached GetClassNode getClassNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ public abstract static class BytesInitNode extends PNodeWithContext {

public abstract byte[] execute(VirtualFrame frame, Node inliningTarget, Object source, Object encoding, Object errors);

@Specialization
static byte[] none(@SuppressWarnings("unused") PNone source, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors) {
@Specialization(guards = "isNoValue(source)")
static byte[] noValue(@SuppressWarnings("unused") PNone source, @SuppressWarnings("unused") PNone encoding, @SuppressWarnings("unused") PNone errors) {
return PythonUtils.EMPTY_BYTE_ARRAY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ public final Object execute(VirtualFrame frame, Object self, Object[] arguments,
PNone init(VirtualFrame frame, SuperObject self, Object cls, Object obj,
@Bind Node inliningTarget,
@Cached @Exclusive PRaiseNode raiseNode) {
if (!ensureIsTypeNode().executeCached(cls)) {
throw raiseNode.raise(inliningTarget, PythonErrorType.TypeError, ErrorMessages.FIRST_ARGUMENT_MUST_BE_A_TYPE_OBJECT_NOT_P, cls);
}
if (!(obj instanceof PNone)) {
Object type = supercheck(frame, inliningTarget, cls, obj, raiseNode);
self.init(cls, type, obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ static Object readAttributeQuickly(Object type, TpSlots slots, Object receiver,
PythonAbstractClass base = bases[0];
if (base instanceof PythonBuiltinClass &&
((PythonBuiltinClass) base).getType() == PythonBuiltinClassType.PythonObject) {
if (!(codePointAtIndexNode.execute(stringName, 0) == '_' && codePointAtIndexNode.execute(stringName, 1) == '_')) {
int length = codePointLengthNode.execute(stringName, TS_ENCODING);
if (!(length >= 2 && codePointAtIndexNode.execute(stringName, 0) == '_' && codePointAtIndexNode.execute(stringName, 1) == '_')) {
// not a special name, so this attribute cannot be inherited, and can
// only be on the type or the object. If it's on the type, return to
// the generic code.
Expand Down
Loading