Skip to content

Conversation

tiangolo
Copy link
Contributor

🎨 Fix type annotation for ignore_errors in sentry_sdk.init().

This would be a valid example using Sentry:

from typing import List
import sentry_sdk


class BaseError(Exception):
    pass


class AuthError(BaseError):
    pass


class UserError(BaseError):
    pass


ignored_errors: list[type[BaseError]] = [AuthError, UserError]

sentry_sdk.init(dsn="notreallyadsn", ignore_errors=ignored_errors)

But mypy / type annotation tools would complain that it's not valid because "List is invariant", so it's much more strict about expecting the exact types and type parameters it defines.

Argument "ignore_errors" to "init" has incompatible type "List[type]"; expected "List[Union[type, str]]"  [arg-type]mypy(error)
"List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variancemypy(note)
Consider using "Sequence" instead, which is covariantmypy(note)

After this change that error goes away.

@antonpirker antonpirker enabled auto-merge (squash) March 6, 2023 08:23
@antonpirker antonpirker self-assigned this Mar 6, 2023
@antonpirker antonpirker merged commit a135fd6 into getsentry:master Mar 6, 2023
@tiangolo tiangolo deleted the ignore-errors-types branch March 14, 2023 15:53
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