Skip to content
Merged
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
10 changes: 7 additions & 3 deletions atom/src/atomdict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,21 @@ PyObject* AtomDict_setdefault( AtomDict* self, PyObject* args )
cppy::ptr key_ptr( validate_key( self, key ) );
if ( !key_ptr )
return 0;
PyObject* value = PyDict_GetItem( pyobject_cast( self ), key_ptr.get() );
PyObject* value = PyDict_GetItemWithError( pyobject_cast( self ), key_ptr.get() );
if( value )
{
return cppy::incref( value );
}
if( PyErr_Occurred() )
{
return 0;
}
if( AtomDict_ass_subscript( self, key_ptr.get(), dfv ) < 0 )
{
return 0;
}
// Get the dictionary from the dict itself in case it was coerced.
return cppy::incref( PyDict_GetItem( pyobject_cast( self ), key_ptr.get() ) );
return cppy::xincref( PyDict_GetItemWithError( pyobject_cast( self ), key_ptr.get() ) );
}


Expand Down Expand Up @@ -310,7 +314,7 @@ static PyObject* DefaultAtomDict_missing( DefaultAtomDict* self, PyObject* key )
return 0;
}
// Get the dictionary from the dict itself in case it was coerced.
value_ptr = cppy::incref( PyDict_GetItem( pyobject_cast( self ), key_ptr.get() ) );
value_ptr = cppy::xincref( PyDict_GetItem( pyobject_cast( self ), key_ptr.get() ) );
}
return value_ptr.release();
}
Expand Down
4 changes: 4 additions & 0 deletions atom/src/atomlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,11 @@ class AtomCListHandler : public AtomListHandler
// if the superclass call succeeds, then this is safe.
Py_ssize_t i = -1;
if( nargs == 1 )
{
i = PyLong_AsSsize_t( args[0] );
if( PyErr_Occurred() )
return 0;
}
if( i < 0 )
i += size;
cppy::ptr index( PyLong_FromSsize_t( i ) );
Expand Down
1 change: 1 addition & 0 deletions releasenotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Atom Release Notes
-------------------

- add support for type aliases in annotations used to generate a member PR #280
- fix corner cases in C API closing #277 and #278 PR #279

0.13.0 - 09/10/2026
-------------------
Expand Down
2 changes: 1 addition & 1 deletion test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mypy
pyrefly
ty
pytest
pytest < 9.2
pytest-cov
pytest-benchmark
psutil
12 changes: 12 additions & 0 deletions tests/test_atomdefaultdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ class A(Atom):
assert content is a.d[1]


def test_missing_raises_key_hash_error():
class BadKey:
def __hash__(self):
raise RuntimeError("hash failed")

class A(Atom):
d = DefaultDict(missing=int)

with pytest.raises(RuntimeError, match="hash failed"):
A().d[BadKey()]


def test_update(default_atom_dict):
"""Test update a dict."""
default_atom_dict.untyped.update({"": 1})
Expand Down
10 changes: 10 additions & 0 deletions tests/test_atomlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,16 @@ def test_container_pop(container_model, kind):
assert change["item"] == 0


def test_container_pop_index_object_raises_typeerror():
model = ContainerModel()
model.untyped = [10, 20, 30]
model.typed = [10, 20, 30]
with pytest.raises(TypeError):
model.untyped.pop(Indexer(0))
with pytest.raises(TypeError):
model.typed.pop(Indexer(0))


@pytest.mark.parametrize("kind", ("untyped", "typed"))
def test_container_reverse(container_model, kind):
mlist = getattr(container_model, kind)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_mem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_mem_usage(label):
# Allow slight memory decrease over time to make tests more resilient
if first_info != last_info:
# Allow a small increase in RSS to account for memory fluctuations
assert (first_info.rss + 200e3) >= last_info.rss >= 0, (
assert (first_info.rss + 400e3) >= last_info.rss >= 0, (
"Memory leaked:\n {}\n {}".format(first_info, last_info)
)
assert first_info.vms >= last_info.vms >= 0, (
Expand Down
Loading