FEAT: Add to_dict(), keys(), values(), items(), __contains__ to Row #613
FEAT: Add to_dict(), keys(), values(), items(), __contains__ to Row #613jahnvi480 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Adds dict-like helpers (keys(), values(), items(), to_dict()) and __contains__ to the Row class so rows behave more like mappings, addressing issue #606. New unit tests cover each helper and the case-insensitive membership path.
Changes:
- Add
keys(),values(),items(),to_dict()toRow, sourced fromself._column_mapandself._values. - Add
__contains__with case-insensitive fallback viaself._column_map_lower. - Add four new tests in
tests/test_001_globals.pyexercising the helpers andinoperator (case-sensitive and case-insensitive).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mssql_python/row.py | Implements the new mapping-style methods and membership protocol on Row. |
| tests/test_001_globals.py | Adds tests for to_dict, keys/values/items, and __contains__ (case-sensitive + insensitive). |
Key concern: in real cursor-built rows, _column_map stores each column under both its original-cased name and a lowercase alias, so keys()/items()/to_dict() will emit each column twice and len(keys()) != len(values()). The new tests use a hand-built column_map without the lowercase aliases, so they don't catch this — see the inline comment for details and suggested directions.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/row.pyLines 85-93 85 if idx not in idx_to_name:
86 idx_to_name[idx] = name
87 self._column_names = tuple(idx_to_name[i] for i in sorted(idx_to_name))
88 else:
! 89 self._column_names = ()
90
91 def _stringify_uuids(self, indices):
92 """
93 Convert uuid.UUID values at the given column indices to uppercase str in-place.📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.pybind.ddbc_bindings.h: 59.7%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.ddbc_bindings.cpp: 76.1%
mssql_python.__init__.py: 77.3%
mssql_python.pybind.connection.connection.cpp: 77.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.row.py: 81.2%
mssql_python.logging.py: 85.5%
mssql_python.connection.py: 85.6%🔗 Quick Links
|
Work Item / Issue Reference
Summary
This pull request adds new dictionary-like methods and membership testing to the
Rowclass inmssql_python/row.py, and introduces corresponding unit tests to ensure their correct behavior. These enhancements makeRowinstances more intuitive and compatible with Python's mapping protocol, improving usability and testability.Enhancements to the
Rowclass:keys(),values(), anditems()methods toRow, allowing access to column names, values, and (name, value) pairs in a dictionary-like fashion.to_dict()method to return the row as a plain dictionary mapping column names to values.inoperator to test for column membership, including case-insensitive matching when a lowercase column map is provided.Testing improvements:
to_dict(),keys(),values(), anditems()methods to verify they behave like theirdictcounterparts.inoperator, including both case-sensitive and case-insensitive membership checks.