Skip to content

Comments

Adding type hints and docstrings#317

Merged
mindflayer merged 14 commits intomainfrom
typehints-and-docstrings
Feb 22, 2026
Merged

Adding type hints and docstrings#317
mindflayer merged 14 commits intomainfrom
typehints-and-docstrings

Conversation

@mindflayer
Copy link
Owner

@mindflayer mindflayer commented Feb 22, 2026

Completing what was requested in #203.

@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 (3a184d5) to head (119d3b8).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #317      +/-   ##
==========================================
+ Coverage   99.04%   99.06%   +0.01%     
==========================================
  Files          22       22              
  Lines        1051     1073      +22     
==========================================
+ Hits         1041     1063      +22     
  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.

Copy link

Copilot AI left a 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 pull request adds type hints and docstrings throughout the Mocket codebase in response to issue #203, which requested improved code readability and static type checking support. The changes primarily consist of:

  1. Adding comprehensive docstrings following Google/NumPy style to all public methods and classes
  2. Adding type hints to function signatures and class attributes
  3. Reorganizing imports in test files to follow PEP 8 conventions (stdlib → third-party → mocket submodules → mocket main package)

Changes:

  • Added module-level docstrings to all mocket source files
  • Added comprehensive function and method docstrings with Args, Returns, and Raises sections
  • Added type hints using modern Python syntax (PEP 604 union types, etc.)
  • Reorganized imports in test files for consistency
  • Removed minor whitespace inconsistencies
  • Removed pragma: no cover comment from send method after adding proper documentation
  • Added explicit return type annotation for MocketSocketIO.write()

Reviewed changes

Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/test_utils.py Removed extra blank line in imports
tests/test_socket.py Reorganized imports (mocket.socket before mocket main)
tests/test_redis.py Reorganized imports (mocket.mockredis before mocket main)
tests/test_pook.py Removed extra blank line in imports
tests/test_mode.py Reorganized imports (mocket submodules before mocket main)
tests/test_mocket.py Reorganized imports (mocket.compat before mocket main)
tests/test_httpx.py Reorganized imports (mocket submodules before mocket main)
tests/test_https.py Reorganized imports (mocket.mockhttp before mocket main)
tests/test_httpretty.py Reorganized imports (mocket.plugins before sure)
tests/test_http_httpx.py Removed extra blank line in imports
tests/test_http.py Reorganized imports (mocket.mocks.mockhttp before mocket main)
tests/test_asyncio.py Reorganized imports (mocket submodules before mocket main)
mocket/utils.py Added module docstring, improved docstrings for hexdump/hexload/get_mocketize
mocket/urllib3.py Added module docstring and function docstrings
mocket/types.py Added module docstring
mocket/ssl/socket.py Added class/method docstrings and type hints for MocketSSLSocket
mocket/ssl/context.py Added class/method docstrings and type hints for SSL context classes
mocket/socket.py Added comprehensive docstrings and type hints for MocketSocket, removed FIXME comment
mocket/recording.py Added module docstring, class/method docstrings and type hints
mocket/mode.py Added module docstring and method docstrings for _MocketMode
mocket/mocks/mockredis.py Added module/class/method docstrings and type hints
mocket/mocks/mockhttp.py Added module/class/method docstrings and type hints
mocket/mocket.py Added module docstring and method docstrings for Mocket singleton
mocket/io.py Added module/class/method docstrings, added return statement to write()
mocket/inject.py Added module docstring and function docstrings
mocket/exceptions.py Added module docstring and exception class docstrings
mocket/entry.py Added module/class/method docstrings and type hints
mocket/decorators/mocketizer.py Added module/class/method docstrings and type hints
mocket/decorators/async_mocket.py Added module docstring and function docstrings
mocket/compat.py Added function docstrings with Args/Returns sections
mocket/init.py Added module docstring

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mindflayer
Copy link
Owner Author

mindflayer commented Feb 22, 2026

@copilot Please revert the lines where we got rid of doctests.

Copy link

Copilot AI commented Feb 22, 2026

@mindflayer I've opened a new pull request, #318, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI and others added 12 commits February 22, 2026 21:16
* Initial plan

* Restore doctests in mockhttp.py for set_extra_headers, can_handle, and _parse_requestline

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

* Add coverage.xml to .gitignore and remove from tracking

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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
Removed duplicate import of Mocketizer and mocketize.
Removed duplicate import statements for Mocketizer and async_mocketize.
Removed duplicate import statements for Mocket.
Copy link

Copilot AI commented Feb 22, 2026

@mindflayer I've opened a new pull request, #319, to work on those changes. Once the pull request is ready, I'll request review from you.

* Initial plan

* Fix setsockopt signature to match standard socket API

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

* Add tests for setsockopt with and without optlen

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

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: mindflayer <527325+mindflayer@users.noreply.github.com>
@sonarqubecloud
Copy link

@mindflayer mindflayer merged commit 6407df7 into main Feb 22, 2026
12 checks passed
@mindflayer mindflayer deleted the typehints-and-docstrings branch February 22, 2026 21:45
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