Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions encord/objects/answers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from __future__ import annotations

import warnings
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any, Dict, Generic, Iterable, List, NoReturn, Optional, Set, TypeVar, Union
Expand All @@ -27,7 +28,7 @@
from encord.objects.frames import Ranges, ranges_to_list
from encord.objects.ontology_element import _get_element_by_hash
from encord.objects.options import FlatOption, NestableOption
from encord.objects.utils import _lower_snake_case, short_uuid_str
from encord.objects.utils import _lower_snake_case

ValueType = TypeVar("ValueType")
AttributeType = TypeVar("AttributeType", bound=Attribute)
Expand All @@ -42,7 +43,16 @@ class Answer(ABC, Generic[ValueType, AttributeType]):
def __init__(self, ontology_attribute: AttributeType, track_hash: Optional[str] = None):
self._answered = False
self._ontology_attribute = ontology_attribute
self._track_hash = track_hash or short_uuid_str()

# DEPRECATED: the track_hash parameter is deprecated and will be removed in a future release
if track_hash is not None:
warnings.warn(
"The 'track_hash' parameter is deprecated and will be removed in a future release. "
"It is no longer used by the Encord platform.",
category=DeprecationWarning,
stacklevel=2,
)
Comment on lines +48 to +54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This deprecation warning is currently unreachable. The Answer class is an abstract base class and cannot be instantiated directly. Its concrete subclasses (TextAnswer, RadioAnswer, etc.) define __init__ methods that do not accept a track_hash argument. Consequently, super().__init__ is always called with track_hash as None, and this warning is never triggered.

To make the deprecation warning functional, the __init__ methods of all Answer subclasses should be updated to accept and pass on the track_hash argument.

For example, for TextAnswer:

# In encord/objects/answers.py
class TextAnswer(Answer[str, TextAttribute]):
    def __init__(self, ontology_attribute: TextAttribute, track_hash: Optional[str] = None):
        super().__init__(ontology_attribute, track_hash=track_hash)
        self._value: Optional[str] = None

This change (and similar ones for RadioAnswer, ChecklistAnswer, and NumericAnswer) is needed to allow users to pass the track_hash parameter and receive the deprecation warning.


self._is_manual_annotation = DEFAULT_MANUAL_ANNOTATION
self._should_propagate = False

Expand Down Expand Up @@ -118,7 +128,7 @@ def _get_encord_dynamic_fields(self, ranges: Ranges) -> Dict[str, Any]:
"dynamic": True,
"range": ranges_to_list(ranges),
"shouldPropagate": self._should_propagate,
"trackHash": self._track_hash,
"trackHash": "", # DEPRECATED: trackHash is deprecated
}


Expand Down
Loading