Supporting type imports
See original GitHub issueI 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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Event
is currentlyDict[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.
As this issue was resolved in Feb 2021 and the original poster was happy with the resolution, I close this issue.