Skip to content

Commit

Permalink
celery: remove deprecated import of ContextManager from typing (#3145)
Browse files Browse the repository at this point in the history
* celery: remove deprecated import of ContextManager from typing

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* add type checking

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

* ruff

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>

---------

Signed-off-by: emdneto <9735060+emdneto@users.noreply.github.com>
  • Loading branch information
emdneto authored Dec 24, 2024
1 parent 375eb6f commit 396aad9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import annotations

import logging
from typing import ContextManager, Optional, Tuple
from typing import TYPE_CHECKING, Optional, Tuple

from celery import registry # pylint: disable=no-name-in-module
from celery.app.task import Task

from opentelemetry.semconv.trace import SpanAttributes
from opentelemetry.trace import Span

if TYPE_CHECKING:
from contextlib import AbstractContextManager

logger = logging.getLogger(__name__)

# Celery Context key
Expand Down Expand Up @@ -123,7 +128,7 @@ def attach_context(
task: Optional[Task],
task_id: str,
span: Span,
activation: ContextManager[Span],
activation: AbstractContextManager[Span],
token: Optional[object],
is_publish: bool = False,
) -> None:
Expand Down Expand Up @@ -171,7 +176,7 @@ def detach_context(task, task_id, is_publish=False) -> None:

def retrieve_context(
task, task_id, is_publish=False
) -> Optional[Tuple[Span, ContextManager[Span], Optional[object]]]:
) -> Optional[Tuple[Span, AbstractContextManager[Span], Optional[object]]]:
"""Helper to retrieve an active `Span`, `ContextManager` and context token
stored in a `Task` instance
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
amqp==5.2.0
asgiref==3.8.1
billiard==4.2.0
billiard==4.2.1
celery==5.3.6
click==8.1.7
click-didyoumean==0.3.0
Expand Down

0 comments on commit 396aad9

Please sign in to comment.