enthought / enthought/apptools

Preferences can't be unset if they are the only one on a given node.

Open
#312 2 comments 0 reactions 0 assignees View on GitHub
type: bug
Dominant language
Python
Stars
38
Forks
21
PR merge metrics
No merged PRs in 30d

Description

From the [`IPreference` documentation](https://docs.enthought.com/apptools/api/apptools.preferences.i_preferences.html#apptools.preferences.i_preferences.IPreferences), it's unclear to me whether I should use `preferences.clear(key)` or `preferences.remove(key)` to un-set a preference.

However, it looks as though neither works.

Is it possible to remove a preference altogether? And if so, should one of these two methods work to that end?

**Expected**

For preferences that are stored to file, if there is a preference at some key (namespace.key), it should be possible to remove that preference altogether.

Consider this initial situation:

```python
>>> def cat(fname):
... with open(fname, "r") as f:
... print(f.read())
...
>>> preferences = Preferences(filename="example.ini")
>>> preferences.set("namespace.field", "value")
>>> preferences.flush()
>>> cat("example.ini")
[namespace]
field = value
```

I would expect that

```python
preferences.remove("namespace.field")
preferences.flush()
```

would result in a empty `example.ini` file.

**Observed**

Neither approach works:
```python
>>> preferences.remove("namespace.field")
>>> preferences.flush()
>>> cat("example.ini")
[namespace]
field = value

>>> preferences.clear("namespace.field")
>>> preferences.flush()
>>> cat("example.ini")
[namespace]
field = value

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.