Skip to content

Commit e8a9101

Browse files
committed
Replace atlas4py.Config.from_kwargs with constructor
1 parent 4b7dad2 commit e8a9101

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/atlas4py/_atlas4py_Config.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,14 +276,13 @@ void atlas4py::bind_Config( nb::module_& m ) {
276276

277277
nb::class_<atlas::util::Config, eckit::LocalConfiguration>( m, "Config" )
278278
.def( nb::init() )
279-
.def_static( "from_kwargs", []( nb::kwargs kwargs ) {
280-
atlas::util::Config config;
279+
.def( "__init__", []( atlas::util::Config* config, nb::kwargs kwargs ) {
280+
new ( config ) atlas::util::Config();
281281
for( const auto& pair : kwargs ) {
282282
const auto key = nb::cast<std::string>(pair.first);
283283
const auto& value = pair.second;
284-
config_set(config, key, value);
284+
config_set(*config, key, value);
285285
}
286-
return config;
287286
} )
288287
.def_static( "from_yaml", []( std::string const& yaml ) {
289288
return atlas::util::Config( eckit::YAMLConfiguration(yaml) );

tests/test_bindings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_config_set_python_types():
211211
assert [dict(d) for d in c["list_of_dicts"]] == [{"a": 1}, {"b": 2}]
212212

213213
def test_config_contains():
214-
config = atlas4py.Config.from_kwargs(option1="value1", option2=42)
214+
config = atlas4py.Config(option1="value1", option2=42)
215215
assert "option1" in config
216216
assert "option2" in config
217217
assert "option3" not in config
@@ -223,7 +223,7 @@ def test_config_contains():
223223

224224

225225
def test_config_mapping_protocol():
226-
config = atlas4py.Config.from_kwargs(option1="value1", option2=42, option3=3.14)
226+
config = atlas4py.Config(option1="value1", option2=42, option3=3.14)
227227
# dict() uses keys() + __getitem__
228228
d = dict(config)
229229
assert d == {"option1": "value1", "option2": 42, "option3": 3.14}
@@ -244,8 +244,8 @@ def test_config_mapping_errors():
244244
config["unsupported"] = value
245245

246246

247-
def test_config_from_kwargs():
248-
config = atlas4py.Config.from_kwargs(option1="value1", option2=42)
247+
def test_config_constructor_with_kwargs():
248+
config = atlas4py.Config(option1="value1", option2=42)
249249
config["option3"] = 3.14
250250
assert config["option1"] == "value1"
251251
assert config["option2"] == 42

0 commit comments

Comments
 (0)