Skip to content

FlatDict "leaf" nodes in output of as_dict() #59

Description

@jpo-tu

version info:

$ python --version
Python 3.12.1
$ pip show flatdict
Name: flatdict
Version: 4.0.1
Summary: Python module for interacting with nested dicts as a single level dict with delimited keys.
Home-page: https://github.com/gmr/flatdict
Author: Gavin M. Roy
Author-email: gavinmroy@gmail.com
License: BSD 3-Clause License
Location: /usr/local/python/3.12.1/lib/python3.12/site-packages
Requires: 
Required-by:

Summary: as_dict() returns empty "leaf" dicts as FlatDict instances if key path contains an odd number of segments

Reproduce:

from flatdict import FlatDict
print(FlatDict({'a': {}}).as_dict())

Expected output:

{'a': {}}

Actual output:

{'a': <FlatDict id=139946220524928 {}>"}

If the key path contains an even number of segments the issue is not present:

from flatdict import FlatDict

FlatDict({'a': {}}).as_dict()
# {'a': <FlatDict id=140045793698368 {}>"}

FlatDict({'a': {'b': {}}}).as_dict()
# {'a': {'b': {}}}

FlatDict({'a': {'b': {'c': {}}}}).as_dict()
# {'a': {'b': {'c': <FlatDict id=140045792487056 {}>"}}}

FlatDict({'a': {'b': {'c': {'d':{}}}}}).as_dict()
# {'a': {'b': {'c': {'d': {}}}}}

# various, etc

Other information:

  • I also tested with flatdict==3.4.0 and python 3.9 and the issue is present

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions