Skip to content

feat: Add type hints to public API - #136

Merged
TheRealAgentK merged 4 commits into
masterfrom
feature/#135-type-hints
Jan 20, 2026
Merged

feat: Add type hints to public API#136
TheRealAgentK merged 4 commits into
masterfrom
feature/#135-type-hints

Conversation

@TheRealAgentK

@TheRealAgentK TheRealAgentK commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

Summary

Add comprehensive type annotations to the core public API for improved AI/IDE support, static analysis, and developer experience.

NOTE: This PR is based on the changes in PR #125 (because I anticipated that there would be changes to tests required).

Changes

Type-annotated modules:

  • raygunprovider.py - RaygunSender, RaygunHandler with full type hints
  • raygunmsgs.py - RaygunMessage, RaygunMessageBuilder, RaygunErrorMessage
  • utilities.py - All utility functions typed
  • http_utilities.py - HTTP request handling typed

Infrastructure:

  • Added py.typed marker for PEP 561 compliance
  • Added mypy configuration in pyproject.toml
  • Added mypy and types-requests to dev dependencies

Testing

  • ✅ All 93 tests pass
  • ✅ mypy passes with no errors
  • ✅ Build succeeds

Future work

Type hints for middleware (Flask, Django, WSGI) and CLI are planned for a follow-up PR.

Closes #135

- Replace unittest2 (Python 2 backport) with pytest
- Replace coverage with pytest-cov
- Remove mock dependency (built into Python 3.3+)
- Add pytest configuration to pyproject.toml
- Update CI workflow to use pytest
- Update CONTRIBUTING.MD with pytest commands
- Mark functional tests to skip when RAYGUN_API_KEY not set
- Refactor global variable tests to use direct injection instead of
  relying on module globals (fixes pytest compatibility)
The standalone mock package was removed as a dependency since it's
built into Python 3.3+. Updated remaining test files that were still
using the external import.
Add comprehensive type annotations to the core public API:
- raygunprovider.py: RaygunSender, RaygunHandler with full type hints
- raygunmsgs.py: RaygunMessage, RaygunMessageBuilder, RaygunErrorMessage
- utilities.py: All utility functions typed
- http_utilities.py: HTTP request handling typed

Also includes:
- py.typed marker for PEP 561 compliance
- mypy configuration in pyproject.toml
- mypy and types-requests added to dev dependencies

Type checking is currently enabled for the core modules only.
Middleware and CLI are excluded pending future work.

Copilot AI left a comment

Copy link
Copy Markdown

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 adds comprehensive type hints to the core public API of the raygun4py library, improving IDE support, static analysis capabilities, and overall developer experience.

Changes:

  • Added type annotations to core modules (raygunprovider.py, raygunmsgs.py, utilities.py, http_utilities.py)
  • Configured mypy for static type checking with strict settings
  • Migrated test infrastructure from unittest to pytest with coverage support

Reviewed changes

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

Show a summary per file
File Description
python3/tests/test_raygunmsgs.py Refactored tests to directly inject global variables instead of using actual globals, improving test isolation
python3/tests/test_functional.py Replaced unittest-based skip logic with pytest decorator
python3/tests/middleware/test_wsgi.py Updated mock import to use standard library's unittest.mock
python3/tests/middleware/test_django.py Updated mock import to use standard library's unittest.mock
python3/raygun4py/utilities.py Added comprehensive type hints with forward references
python3/raygun4py/raygunprovider.py Added type hints to all methods and introduced type aliases for clarity
python3/raygun4py/raygunmsgs.py Added type hints to message classes and builder pattern
python3/raygun4py/http_utilities.py Added type hints to HTTP utility functions
pyproject.toml Added mypy configuration and migrated from unittest2 to pytest
CONTRIBUTING.MD Updated testing instructions to use pytest
.github/workflows/python-checks.yml Updated CI to use pytest instead of unittest

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

Comment thread python3/raygun4py/raygunmsgs.py
Comment thread python3/raygun4py/raygunprovider.py

@miquelbeltran miquelbeltran left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I LOVE TYPES!!!!!

@TheRealAgentK
TheRealAgentK merged commit 68c89c0 into master Jan 20, 2026
7 checks passed
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.

Type hints: Add type hints to Raygun4Py for better AI/IDE support (experimental)

4 participants