From 9476cb193758e82aaaa1227cf762a467d7e43c83 Mon Sep 17 00:00:00 2001 From: Kiran K Kotari Date: Thu, 1 Jan 2026 01:25:19 -0500 Subject: [PATCH] parse tree bug fix --- CHANGELOG.md | 8 ++++++++ pyproject.toml | 2 +- shconfparser/__init__.py | 2 +- shconfparser/parser.py | 9 +++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b036fdd..3022789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.1.1] - 2026-01-01 + +### Fixed +- 🐛 **Parser tree conversion** - Fixed TypeError in `_tree_to_yaml_structure` method + - Added proper handling for path navigation conflicts when a key exists as non-dict value + - Added conflict resolution for identifier assignment when overwriting existing values + - Improved robustness when processing configuration files with conflicting key structures + ## [3.1.0] - 2025-12-28 ### 🎉 Format System Refinement diff --git a/pyproject.toml b/pyproject.toml index 041ee02..e4bfd9f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "shconfparser" -version = "3.1.0" +version = "3.1.1" description = "Network configuration parser that translates show command outputs into structured data" readme = "README.md" requires-python = ">=3.9" diff --git a/shconfparser/__init__.py b/shconfparser/__init__.py index 314e7e3..b333f2e 100644 --- a/shconfparser/__init__.py +++ b/shconfparser/__init__.py @@ -41,7 +41,7 @@ from .tree_parser import TreeParser from .xpath import XPath -__version__ = "3.1.0" +__version__ = "3.1.1" __author__ = "Kiran Kumar Kotari" __email__ = "kirankotari@live.com" diff --git a/shconfparser/parser.py b/shconfparser/parser.py index 830e055..175d308 100644 --- a/shconfparser/parser.py +++ b/shconfparser/parser.py @@ -349,9 +349,17 @@ def _tree_to_yaml_structure(self, tree: TreeData) -> Dict[str, Any]: for part in path_parts: if part not in current: current[part] = {} + elif not isinstance(current[part], dict): + # Key exists as non-dict, convert to dict + current[part] = {} current = current[part] # Add the identifier with its nested value + # Check if identifier already exists and handle conflicts + if identifier in current and not isinstance(current[identifier], dict): + # Identifier exists as non-dict, we'll overwrite it + # This handles cases where a leaf value conflicts with a container + pass current[identifier] = self._tree_to_yaml_structure(value) else: @@ -360,6 +368,7 @@ def _tree_to_yaml_structure(self, tree: TreeData) -> Dict[str, Any]: # Two words: first is key, second is value # "hostname R1" → hostname: R1 # "duplex auto" → duplex: auto + # Overwrite any existing value (dict or otherwise) result[parts[0]] = parts[1] elif len(parts) > 2: