From ab0c32e284e0ecb7e8719595e5add3314bbe8292 Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 18 Mar 2024 09:21:09 +0100 Subject: [PATCH 1/3] Fixed OpenAI tests (#2834) This will prevent the streaming reponse OpenAI tests to fail. --- tests/integrations/openai/test_openai.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index d9a239e004..074d859274 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -99,7 +99,7 @@ def test_streaming_chat_completion( events = capture_events() client = OpenAI(api_key="z") - returned_stream = Stream(cast_to=None, response=None, client=None) + returned_stream = Stream(cast_to=None, response=None, client=client) returned_stream._iterator = [ ChatCompletionChunk( id="1", From 9dc517b7dd3224d5d6b708cc87671b2dbda644f5 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Mon, 18 Mar 2024 09:44:44 +0100 Subject: [PATCH 2/3] Re-export `Event` in `types.py` (#2829) End-users may need to use the Event type for their type hinting to work following the Event type changes. However, we define Event in a private module sentry_sdk._types, which provides no stability guarantees. Therefore, this PR creates a new public module sentry_sdk.types, where we re-export the Event type, and explicitly make it available as public API via sentry_sdk.types.Event. The new sentry_sdk.types module includes a docstring to inform users that we reserve the right to modify types in minor releases, since we consider types to be a form of documentation (they are not enforced by the Python language), but that we guarantee that we will only remove type definitions in a major release. --- sentry_sdk/types.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 sentry_sdk/types.py diff --git a/sentry_sdk/types.py b/sentry_sdk/types.py new file mode 100644 index 0000000000..5c46de7f88 --- /dev/null +++ b/sentry_sdk/types.py @@ -0,0 +1,14 @@ +""" +This module contains type definitions for the Sentry SDK's public API. +The types are re-exported from the internal module `sentry_sdk._types`. + +Disclaimer: Since types are a form of documentation, type definitions +may change in minor releases. Removing a type would be considered a +breaking change, and so we will only remove type definitions in major +releases. +""" + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from sentry_sdk._types import Event, Hint # noqa: F401 From 9bdd029cc7dd5d4a698e92a0883e601a01d760ee Mon Sep 17 00:00:00 2001 From: Anton Pirker Date: Mon, 18 Mar 2024 10:30:12 +0100 Subject: [PATCH 3/3] Small APIdocs improvement (#2828) This PR makes sure all apidocs are recreated always (by deleting an eventually existing docs/_build folder) and also adds some minor changes to set_level and set_tag to make the types of parameters clear. --- Makefile | 1 + sentry_sdk/scope.py | 55 +++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 32cdbb1fff..ac0ef51f5f 100644 --- a/Makefile +++ b/Makefile @@ -51,6 +51,7 @@ lint: .venv apidocs: .venv @$(VENV_PATH)/bin/pip install --editable . @$(VENV_PATH)/bin/pip install -U -r ./docs-requirements.txt + rm -rf docs/_build @$(VENV_PATH)/bin/sphinx-build -vv -W -b html docs/ docs/_build .PHONY: apidocs diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 80537cd8bf..cd974e4a52 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -441,13 +441,28 @@ def clear(self): @_attr_setter def level(self, value): - # type: (Optional[LogLevelStr]) -> None - """When set this overrides the level. Deprecated in favor of set_level.""" + # type: (LogLevelStr) -> None + """ + When set this overrides the level. + + .. deprecated:: 1.0.0 + Use :func:`set_level` instead. + + :param value: The level to set. + """ + logger.warning( + "Deprecated: use .set_level() instead. This will be removed in the future." + ) + self._level = value def set_level(self, value): - # type: (Optional[LogLevelStr]) -> None - """Sets the level for the scope.""" + # type: (LogLevelStr) -> None + """ + Sets the level for the scope. + + :param value: The level to set. + """ self._level = value @_attr_setter @@ -555,20 +570,24 @@ def profile(self, profile): self._profile = profile - def set_tag( - self, - key, # type: str - value, # type: Any - ): - # type: (...) -> None - """Sets a tag for a key to a specific value.""" + def set_tag(self, key, value): + # type: (str, Any) -> None + """ + Sets a tag for a key to a specific value. + + :param key: Key of the tag to set. + + :param value: Value of the tag to set. + """ self._tags[key] = value - def remove_tag( - self, key # type: str - ): - # type: (...) -> None - """Removes a specific tag.""" + def remove_tag(self, key): + # type: (str) -> None + """ + Removes a specific tag. + + :param key: Key of the tag to remove. + """ self._tags.pop(key, None) def set_context( @@ -577,7 +596,9 @@ def set_context( value, # type: Dict[str, Any] ): # type: (...) -> None - """Binds a context at a certain key to a specific value.""" + """ + Binds a context at a certain key to a specific value. + """ self._contexts[key] = value def remove_context(