You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FIX: Making type objects and constructor compatible with pyodbc (#157)
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below (e.g.
AB#37452)
For external contributors: Insert Github Issue number below (e.g. #149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#38059](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/38059)
-------------------------------------------------------------------
### Summary
This pull request refactors type objects in `mssql_python/type.py` to
inherit from their respective Python built-in types, simplifies
constructors, and updates related tests to align with the new
implementation. Additionally, it modifies timestamp and time handling
functions for better compatibility and enhances the `Binary` function to
handle multiple input types.
### Refactoring of type objects:
-
[`mssql_python/type.py`](diffhunk://#diff-57fcb124a0b5958b9034fbd0c3ee1bc65e4140e1671e642d5dcb5aabd60d55a7L12-R55):
Changed type classes (`STRING`, `BINARY`, `NUMBER`, `DATETIME`, `ROWID`)
to inherit from Python built-in types (`str`, `bytearray`, `float`,
`datetime.datetime`, `int`) and replaced `__init__` methods with
`__new__` methods for direct instantiation.
### Updates to utility functions:
-
[`mssql_python/type.py`](diffhunk://#diff-57fcb124a0b5958b9034fbd0c3ee1bc65e4140e1671e642d5dcb5aabd60d55a7L93-R113):
Modified `TimeFromTicks` to use `time.localtime` instead of
`time.gmtime` and updated `TimestampFromTicks` to remove the UTC
timezone. Enhanced `Binary` to handle both `str` and `bytes` inputs,
with fallback for other types by converting to string first.
### Updates to tests:
-
[`tests/test_002_types.py`](diffhunk://#diff-15437630102d01c37a02763e0080246da102ccedaeea931d7c433470ff0fb009L6-R19):
Updated tests for type objects (`STRING`, `BINARY`, `NUMBER`,
`DATETIME`, `ROWID`) to validate against their respective Python
built-in types instead of custom attributes.
-
[`tests/test_002_types.py`](diffhunk://#diff-15437630102d01c37a02763e0080246da102ccedaeea931d7c433470ff0fb009L47-R58):
Adjusted `test_time_from_ticks` and `test_timestamp_from_ticks` to
reflect changes in `TimeFromTicks` and `TimestampFromTicks` behavior.
Improved `test_binary_constructor` to test compatibility with both
`bytes` and `bytearray`.
---------
Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
Co-authored-by: Sumit Sarabhai <sumitsar@microsoft.com>
0 commit comments