-
Notifications
You must be signed in to change notification settings - Fork 31
FIX: Making type objects and constructor compatible with pyodbc #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors type objects in mssql_python/type.py to inherit from Python built-in types and makes related utility functions more compatible with pyodbc standards.
- Refactored type classes (
STRING,BINARY,NUMBER,DATETIME,ROWID) to inherit from built-in Python types instead of custom classes - Modified timestamp and time utility functions to use local time instead of UTC
- Enhanced the
Binaryfunction to handle multiple input types (str,bytes, and fallback for others)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mssql_python/type.py | Refactored type classes to inherit from built-ins, updated time functions to use local time, enhanced Binary function |
| tests/test_002_types.py | Updated tests to validate new type inheritance behavior and adjusted time/timestamp test expectations |
sumitmsft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left one comment on how to handle unexpected type in Binary func,
Work Item / Issue Reference
Summary
This pull request refactors type objects in
mssql_python/type.pyto 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 theBinaryfunction to handle multiple input types.Refactoring of type objects:
mssql_python/type.py: 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: ModifiedTimeFromTicksto usetime.localtimeinstead oftime.gmtimeand updatedTimestampFromTicksto remove the UTC timezone. EnhancedBinaryto handle bothstrandbytesinputs, with fallback for other types by converting to string first.Updates to tests:
tests/test_002_types.py: 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: Adjustedtest_time_from_ticksandtest_timestamp_from_ticksto reflect changes inTimeFromTicksandTimestampFromTicksbehavior. Improvedtest_binary_constructorto test compatibility with bothbytesandbytearray.