Skip to content

feat: ensure ServiceInfo.properties always returns bytes#1333

Merged
bdraco merged 3 commits into
masterfrom
properties
Dec 13, 2023
Merged

feat: ensure ServiceInfo.properties always returns bytes#1333
bdraco merged 3 commits into
masterfrom
properties

Conversation

@bdraco
Copy link
Copy Markdown
Member

@bdraco bdraco commented Dec 13, 2023

Clean up ServiceInfo.properties to always return bytes.

This is a technically breaking change. Its seems unlikely anyone is using it this way, but there is always someone. The type for the incoming Dict is missing which makes the interface unclear, and we ended up with a messy mix internally. This PR aims to correct that. Adding the type would likely cause more pain so its not done in this PR

We continue to allow passing in properties as a mix of bytes and str with the type Union[bytes, Dict[Union[str, bytes], Optional[Union[str, bytes]]]], but we will now convert any str to bytes

The typing on properties was very confusing because it could have a mix of bytes and str types, but only bytes would ever come back from the backend and cache. The only way str could happen is if someone manually passed it in. We now ensure all passed in data is converted to bytes which allows downstream to remove a significant amount of code that tried to deal with the mismatched str/bytes values.

Clean up the typing on `ServiceInfo.properties` to always return bytes.

The typing on properties was very confusing because it could have a mix of bytes
and str types, but only bytes would ever come back from the backend and cache.
The only way str could happen is if someone manually passed it in.

We now ensure all passed in data is converted to bytes
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 13, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e2f9f81) 99.77% compared to head (e3a12c5) 99.77%.
Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1333   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files          30       30           
  Lines        3143     3155   +12     
  Branches      524      526    +2     
=======================================
+ Hits         3136     3148   +12     
  Misses          5        5           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bdraco bdraco merged commit d29553a into master Dec 13, 2023
@bdraco bdraco deleted the properties branch December 13, 2023 23:05
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Jan 5, 2024
* Update ironic-lib from branch 'master'
  to 523407eebf22b68a3b1a3926666e8bb24fedf871
  - Merge "Compatibility with zeroconf 0.129.0"
  - Compatibility with zeroconf 0.129.0
    
    From Zeroconf CHANGELOG.md:
    v0.129.0 (2023-12-13)
    
    Feature
    
    * Add decoded_properties method to ServiceInfo
    python-zeroconf/python-zeroconf#1332
    python-zeroconf/python-zeroconf@9b595a1
    * Ensure ServiceInfo.properties always returns bytes
    python-zeroconf/python-zeroconf#1333
    python-zeroconf/python-zeroconf@d29553a
    
    Technically breaking change
    
    * `ServiceInfo.properties` always returns a dictionary with type
    `dict[bytes, bytes | None]` instead of a mix `str` and `bytes`. It was
    only possible to get a mixed dictionary if it was manually passed in
    when `ServiceInfo` was constructed.
    
    Co-Authored-By: Dmitry Tantsur <dtantsur@protonmail.com>
    Change-Id: I7f1a0c3329e5f29ec3e274558e3681142cc2ef78
openstack-mirroring pushed a commit to openstack/ironic-lib that referenced this pull request Jan 5, 2024
From Zeroconf CHANGELOG.md:
v0.129.0 (2023-12-13)

Feature

* Add decoded_properties method to ServiceInfo
python-zeroconf/python-zeroconf#1332
python-zeroconf/python-zeroconf@9b595a1
* Ensure ServiceInfo.properties always returns bytes
python-zeroconf/python-zeroconf#1333
python-zeroconf/python-zeroconf@d29553a

Technically breaking change

* `ServiceInfo.properties` always returns a dictionary with type
`dict[bytes, bytes | None]` instead of a mix `str` and `bytes`. It was
only possible to get a mixed dictionary if it was manually passed in
when `ServiceInfo` was constructed.

Co-Authored-By: Dmitry Tantsur <dtantsur@protonmail.com>
Change-Id: I7f1a0c3329e5f29ec3e274558e3681142cc2ef78
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.

1 participant