question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Supporting type imports

See original GitHub issue

I am currently working in a Python project with strict mypy typechecking that requires functions to be fully typed. In order to implement the before_send callback, I need access to the EventProcessor, Event, and Hint types in order to properly annotate the function’s signature, like so:

def create_handler(exceptions_to_ignore: List[Type[Exception]]) -> EventProcessor:
    def before_send(event: Event, hint: Hint) -> Optional[Event]:
        if "exc_info" in hint:
            _, exc_value, _ = hint["exc_info"]
            if any([isinstance(exc_value, exc) for exc in exceptions]):
                return None
        return event
    return before_send

However, all three of these types are defined in sentry_sdk._types, and the leading underscore implies I should not be importing from that file. Are there any plans to make these (and other) types part of the public API? At the moment, I am forced to use extremely permissive types (like Any), which means my code can’t be statically checked by mypy for correctness.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
untitakercommented, Feb 10, 2021

Event is currently Dict[str, Any], which is not wrong, but if we changed that to be a TypedDict, before_send’s return type would stop typechecking for some people.

That’s a very simple example. We may also just say that type hints are exempt from semver. Not sure.

0reactions
antonpirkercommented, Feb 21, 2022

As this issue was resolved in Feb 2021 and the original poster was happy with the resolution, I close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - TypeScript 3.8
import type only imports declarations to be used for type annotations and declarations. It always gets fully erased, so there's no remnant of...
Read more >
type-only imports — A new TypeScript feature that benefits ...
type -only imports — A new TypeScript feature that benefits Babel users · Adds static type checking to code you would traditionally write...
Read more >
Do I need to use the "import type" feature of TypeScript 3.8 if ...
Short answer: Being more explicit by using import type and export type statements seem to yield explicable benefits by safeguarding against ...
Read more >
typescript-eslint/consistent-type-imports.md at main - GitHub
TypeScript allows specifying a type keyword on imports to indicate that the export exists only in the type system, not at runtime.
Read more >
Support TypeScript 3.8 type-only imports/exports in resolve ...
@Anton Lobov I want to clarify. This will involve an implementation to allow auto-import using type-only syntax for TS 3.8+? I saw the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found