Skip to content

Added initial typehints#494

Open
danielmorell wants to merge 15 commits into
masterfrom
added/typehints
Open

Added initial typehints#494
danielmorell wants to merge 15 commits into
masterfrom
added/typehints

Conversation

@danielmorell
Copy link
Copy Markdown
Collaborator

Description of the change

This PR adds the initial work of getting static type checking with mypy working. Because we support Python 3.9 to 3.14 and have integrations with a lot of frameworks that may or may not exist in the environment, our type imports can be a little messy at times. As much as possible we try not to ignore types.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Maintenance
  • New release

Related issues

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • "Ready for review" label attached to the PR and reviewers assigned
  • Issue from task tracker has a link to this pull request
  • Changes have been reviewed by at least one other engineer

@danielmorell danielmorell requested a review from brianr April 17, 2026 20:55
@danielmorell danielmorell added this to the v1.4.0 milestone Apr 17, 2026
@brianr
Copy link
Copy Markdown
Member

brianr commented Apr 21, 2026

@claude review

Comment thread pyproject.toml Outdated
Comment thread rollbar/logger.py Outdated
Comment thread rollbar/examples/asgi/app.py Outdated
Comment thread rollbar/__init__.py
Comment thread rollbar/__init__.py Outdated
Comment thread rollbar/__init__.py
Comment thread rollbar/__init__.py Outdated
Comment thread rollbar/lib/transforms/__init__.py Outdated
Comment thread rollbar/logger.py Outdated
@brianr
Copy link
Copy Markdown
Member

brianr commented May 5, 2026

@codex please review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a8102b7dca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rollbar/__init__.py
Comment thread rollbar/contrib/fastapi/utils.py Outdated
Comment thread rollbar/__init__.py
Comment thread rollbar/lib/_async.py
Comment thread rollbar/__init__.py Outdated
Comment thread rollbar/lib/type_info.py
Comment thread rollbar/lib/_async.py
Comment thread pyproject.toml
Comment thread rollbar/__init__.py Outdated
Copy link
Copy Markdown
Contributor

@terencehonles terencehonles left a comment

Choose a reason for hiding this comment

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

This looks pretty extensive so that's nice to see. I see a couple things that you may want to consider.

You may want to consistently use from __future__ import annotations across the code. This does change the meaning of the imports at runtime and will require a consumer to resolve them differently, but since you didn't actually export the type comments I think this is a safe change to make and it makes sense to make it everywhere before you do export the type comments.

You're missing the py.typed marker, and you may want to add that. I'm not sure if you're waiting for more complete type coverage to export it.

You may want to lean into from __future__ import annotations by using modern syntax where not in a runtime position. I commented on a few of these and you can use a tool like pyupgrade to migrate these automatically, but it will change more than just the type definitions.

Comment thread rollbar/lib/type_info.py
return DEFAULT

# The keys will be coming from data objects in the payload, so they could be just about anything hashable.
KeyType = Union[str, int, float, binary_type, Hashable]
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.

If you're using from __future__ import annotations does it make sense to just use the newer shorthand syntax:

Suggested change
KeyType = Union[str, int, float, binary_type, Hashable]
KeyType = str | int | float | binary_type | Hashable

Comment thread rollbar/lib/traverse.py
Comment on lines +91 to +92
allowed_circular_reference_types: Optional[type | tuple[type, ...]] = None,
memo: Optional[dict[int, tuple[KeyType, ...]]] = None,
Copy link
Copy Markdown
Contributor

@terencehonles terencehonles May 12, 2026

Choose a reason for hiding this comment

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

If you're using from __future__ import annotations does it make sense to just use the newer shorthand syntax:

Suggested change
allowed_circular_reference_types: Optional[type | tuple[type, ...]] = None,
memo: Optional[dict[int, tuple[KeyType, ...]]] = None,
allowed_circular_reference_types: type | tuple[type, ...] | None = None,
memo: dict[int, tuple[KeyType, ...]] | None = None,


def transform(obj, transforms, key=None, batch_transforms=False):
class Handlers(TypedDict, total=False):
string_handler: Callable
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.

These are all Callable[[Any, Any | None], Any] right? It might make sense to at least type this so that handlers have the right signature (via a typevar HandlerType would allow deduplication).

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.

Add typing stubs for Rollbar SDK

3 participants