NonelessDict

About

NonelessDict is a wrapper around dict that will check if a value is None/empty/False, and not add the key in that case.

The class has a method set_with_strict_none_check() that can be used to set a value and check only for None values.

NonelessOrderedDict is based on NonelessDict and OrderedDict, so the order of key insertion is preserved.

API Reference

Classes:

NonelessDict(*args, **kwargs)

A wrapper around dict that will check if a value is None/empty/False, and not add the key in that case.

NonelessOrderedDict(*args, **kwargs)

A wrapper around OrderedDict that will check if a value is None/empty/False, and not add the key in that case.

Data:

_ND

Invariant TypeVar bound to cawdrey.nonelessdict.NonelessDict.

_NOD

Invariant TypeVar bound to cawdrey.nonelessdict.NonelessOrderedDict.

class NonelessDict(*args, **kwargs)[source]

Bases: MutableBase[~KT, ~VT]

A wrapper around dict that will check if a value is None/empty/False, and not add the key in that case.

Use the set_with_strict_none_check() method to check only for None.

Methods:

__setitem__(key, value)

Set self[key] to value.

copy(**add_or_replace)

Return a copy of the dictionary.

set_with_strict_none_check(key, value)

Set key in the dictionary to value, but skipping None values.

__setitem__(key, value)[source]

Set self[key] to value.

copy(**add_or_replace)[source]

Return a copy of the dictionary.

Return type

~_ND

set_with_strict_none_check(key, value)[source]

Set key in the dictionary to value, but skipping None values.

Parameters
class NonelessOrderedDict(*args, **kwargs)[source]

Bases: MutableBase[~KT, ~VT]

A wrapper around OrderedDict that will check if a value is None/empty/False, and not add the key in that case. Use the set_with_strict_none_check function to check only for None

Methods:

__setitem__(key, value)

Set self[key] to value.

copy(*args, **kwargs)

Return a copy of the dictionary.

set_with_strict_none_check(key, value)

Set key in the dictionary to value, but skipping None values.

__setitem__(key, value)[source]

Set self[key] to value.

copy(*args, **kwargs)[source]

Return a copy of the dictionary.

Return type

~_NOD

set_with_strict_none_check(key, value)[source]

Set key in the dictionary to value, but skipping None values.

Parameters
_ND = TypeVar(_ND, bound=NonelessDict)

Type:    TypeVar

Invariant TypeVar bound to cawdrey.nonelessdict.NonelessDict.

_NOD = TypeVar(_NOD, bound=NonelessOrderedDict)

Type:    TypeVar

Invariant TypeVar bound to cawdrey.nonelessdict.NonelessOrderedDict.