Skip to content

refactor: use 'with' statement for socket handling#2039

Open
skbeh wants to merge 1 commit into
rytilahti:masterfrom
skbeh:socket-context-manager
Open

refactor: use 'with' statement for socket handling#2039
skbeh wants to merge 1 commit into
rytilahti:masterfrom
skbeh:socket-context-manager

Conversation

@skbeh

@skbeh skbeh commented Aug 21, 2025

Copy link
Copy Markdown

Use a 'with' statement to handle socket creation and cleanup.

This ensures that sockets are always closed properly, even when exceptions occur, preventing potential resource leaks.

@codecov

codecov Bot commented Aug 21, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 65 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.27%. Comparing base (507afce) to head (367c8c5).

Files with missing lines Patch % Lines
miio/miioprotocol.py 0.00% 58 Missing and 2 partials ⚠️
miio/push_server/server.py 0.00% 5 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2039   +/-   ##
=======================================
  Coverage   82.26%   82.27%           
=======================================
  Files         197      197           
  Lines       19145    19144    -1     
  Branches     1052     1052           
=======================================
  Hits        15750    15750           
+ Misses       3218     3217    -1     
  Partials      177      177           

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

Use a 'with' statement to handle socket creation and cleanup.

This ensures that sockets are always closed properly, even when exceptions occur, preventing potential resource leaks.
@syssi syssi force-pushed the socket-context-manager branch from ce02ea2 to 367c8c5 Compare June 26, 2026 16:00
with socket.socket(
family=socket.AF_INET, type=socket.SOCK_DGRAM
) as get_ip_socket:
get_ip_socket.bind((self._address, SERVER_PORT))
@rytilahti rytilahti added this to the 0.6.0 milestone Jun 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants