Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃帹 Fix type annotation for ignore_errors in sentry_sdk.init() #1928

Merged
merged 3 commits into from Mar 6, 2023

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.

None yet

2 participants