Skip to content

kvpp: python fixes - #141

Merged
craftablescience merged 3 commits into
craftablescience:mainfrom
cueki:kvpp-python-fixes
Sep 25, 2026
Merged

craftablescience merged 3 commits into
craftablescience:mainfrom
cueki:kvpp-python-fixes

Conversation

@cueki

@cueki cueki commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

While testing the python bindings I ran into a few weird parsing bugs, as well as some nanobind warnings.

This is basically what happens:

from pathlib import Path
from sourcepp import kvpp

LOC = Path("Deadlock/game/core/resource/valve_french.txt")
PCF = Path("tf/particles/eyeboss.pcf")
VDF = Path("Steam/userdata/<id>/config/shortcuts.vdf")

kv = kvpp.KV1(LOC.read_text("utf-8"))
kv[0].key                                                     # '\ufeff"lang"'
kv.get_child("lang", 0)                                       # not found
kvpp.KV1Writer(LOC.read_text("utf-8")).bake().splitlines()[0] # '"\ufeff"lang""'
                                            
kv.get_child("lang") # TypeError: get_child(): incompatible function arguments

kvpp.KV1Binary(VDF.read_bytes()).add_child("new") # TypeError: add_child(): incompatible function arguments

dmx = kvpp.DMX(PCF.read_bytes())
kv1b = kvpp.KV1Binary(VDF.read_bytes()) 
# nanobind: leaked 2 instances!

Fixes:

  • KV1/KV1Writer skip a leading UTF-8 BOM
  • get_child defaults n to 0
  • add_child/add_attribute accept their None default (.none())
  • constructors that take bytes no longer return new(self), which leaked every instance

@craftablescience

Copy link
Copy Markdown
Owner

Oops. thanks!

@craftablescience craftablescience changed the title Kvpp python fixes kvpp: python fixes Sep 25, 2026
@craftablescience
craftablescience merged commit 360226e into craftablescience:main Sep 25, 2026
6 checks passed
@cueki
cueki deleted the kvpp-python-fixes branch September 25, 2026 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants