Skip to content

Comments

Fix setsockopt signature to match standard socket API#319

Merged
mindflayer merged 3 commits intotypehints-and-docstringsfrom
copilot/sub-pr-317
Feb 22, 2026
Merged

Fix setsockopt signature to match standard socket API#319
mindflayer merged 3 commits intotypehints-and-docstringsfrom
copilot/sub-pr-317

Conversation

Copy link

Copilot AI commented Feb 22, 2026

MocketSocket.setsockopt was using (family, type, proto) — socket creation parameters — instead of the standard socket.setsockopt(level, optname, value[, optlen]) signature, making it a non-conforming mock.

Changes

  • Signature fix: setsockopt(family, type, proto)setsockopt(level, optname, value, optlen=None)
  • Body fix: Removed incorrect storage of family/type/proto as instance attributes; now forwards to _true_socket with the correct arguments, handling both 3- and 4-argument call variants
  • Docstring: Updated to reflect correct parameter semantics
  • Tests: Added test_setsockopt_without_optlen and test_setsockopt_with_optlen to tests/test_socket.py to cover both forwarding paths
# Before (wrong — socket creation params, not socket options)
def setsockopt(self, family: int, type: int, proto: int) -> None:
    self._family = family
    self._type = type
    self._proto = proto

# After (matches standard socket.setsockopt API)
def setsockopt(self, level: int, optname: int, value: int | bytes | None, optlen: int | None = None) -> None:
    if self._true_socket:
        if optlen is not None:
            self._true_socket.setsockopt(level, optname, value, optlen)
        else:
            self._true_socket.setsockopt(level, optname, value)

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 22, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • httpbin.local
    • Triggering command: /usr/bin/python python -m pytest tests/test_http.py -q -p no:cacheprovider --no-header (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Update signature to match standard API as per review feedback Fix setsockopt signature to match standard socket API Feb 22, 2026
Copilot AI requested a review from mindflayer February 22, 2026 20:43
@codecov
Copy link

codecov bot commented Feb 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.06%. Comparing base (b74910a) to head (bab96a1).
⚠️ Report is 1 commits behind head on typehints-and-docstrings.

Additional details and impacted files
@@                     Coverage Diff                      @@
##           typehints-and-docstrings     #319      +/-   ##
============================================================
- Coverage                     99.06%   99.06%   -0.01%     
============================================================
  Files                            22       22              
  Lines                          1074     1073       -1     
============================================================
- Hits                           1064     1063       -1     
  Misses                           10       10              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mindflayer mindflayer marked this pull request as ready for review February 22, 2026 20:48
@mindflayer
Copy link
Owner

@copilot add a test that covers the new line for when optlen is not None

Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
Copy link
Author

Copilot AI commented Feb 22, 2026

@copilot add a test that covers the new line for when optlen is not None

Added in commit bab96a1:

  • test_setsockopt_without_optlen — covers the 3-argument path
  • test_setsockopt_with_optlen — covers the optlen is not None branch using a realistic SO_LINGER struct value

@sonarqubecloud
Copy link

@mindflayer mindflayer merged commit 119d3b8 into typehints-and-docstrings Feb 22, 2026
12 checks passed
@mindflayer mindflayer deleted the copilot/sub-pr-317 branch February 22, 2026 21:40
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.

2 participants