Skip to content

Commit 425e1ed

Browse files
committed
Remove deprecated StringHandle string value input/output
1 parent f7f64b9 commit 425e1ed

File tree

2 files changed

+0
-85
lines changed

2 files changed

+0
-85
lines changed

cocotb/handle.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
# -*- coding: utf-8 -*-
3131

3232
import enum
33-
import warnings
3433
from functools import lru_cache
3534
from typing import Optional
3635

@@ -491,14 +490,6 @@ def value(self):
491490
"""The value of this simulation object."""
492491
return self._value
493492

494-
def __str__(self):
495-
if isinstance(self.value, bytes):
496-
StringObject._emit_str_warning(self)
497-
return self.value.decode("ascii")
498-
else:
499-
ModifiableObject._emit_str_warning(self)
500-
return str(self.value)
501-
502493

503494
class NonHierarchyIndexableObject(NonHierarchyObject):
504495
"""A non-hierarchy indexable object.
@@ -770,20 +761,6 @@ def value(self) -> BinaryValue:
770761
def __int__(self):
771762
return int(self.value)
772763

773-
def _emit_str_warning(self):
774-
warnings.warn(
775-
"`str({t})` is deprecated, and in future will return `{t}._path`. "
776-
"To get a string representation of the value, use `str({t}.value)`.".format(
777-
t=type(self).__qualname__
778-
),
779-
FutureWarning,
780-
stacklevel=3,
781-
)
782-
783-
def __str__(self):
784-
self._emit_str_warning()
785-
return str(self.value)
786-
787764

788765
class RealObject(ModifiableObject):
789766
"""Specific object handle for Real signals and variables."""
@@ -928,21 +905,10 @@ def _set_value(self, value, call_sim):
928905
.. versionchanged:: 1.4
929906
Takes :class:`bytes` instead of :class:`str`.
930907
Users are now expected to choose an encoding when using these objects.
931-
As a convenience, when assigning :class:`str` values, ASCII encoding will be used as a safe default.
932908
933909
"""
934910
value, set_action = self._check_for_set_action(value)
935911

936-
if isinstance(value, str):
937-
warnings.warn(
938-
"Handles on string objects will soon not accept `str` objects. "
939-
"Please use a bytes object by encoding the string as you see fit. "
940-
"`str.encode('ascii')` is typically sufficient.",
941-
DeprecationWarning,
942-
stacklevel=2,
943-
)
944-
value = value.encode("ascii") # may throw UnicodeEncodeError
945-
946912
if not isinstance(value, bytes):
947913
raise TypeError(
948914
"Unsupported type for string value assignment: {} ({!r})".format(
@@ -956,20 +922,6 @@ def _set_value(self, value, call_sim):
956922
def value(self) -> bytes:
957923
return self._handle.get_signal_val_str()
958924

959-
def _emit_str_warning(self):
960-
warnings.warn(
961-
"`str({t})` is deprecated, and in future will return `{t}._path`. "
962-
"To access the `bytes` value of this handle, use `{t}.value`.".format(
963-
t=type(self).__qualname__
964-
),
965-
FutureWarning,
966-
stacklevel=3,
967-
)
968-
969-
def __str__(self):
970-
self._emit_str_warning()
971-
return self.value.decode("ascii")
972-
973925

974926
_handle2obj = {}
975927

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
11
# Copyright cocotb contributors
22
# Licensed under the Revised BSD License, see LICENSE for details.
33
# SPDX-License-Identifier: BSD-3-Clause
4-
import pytest
5-
6-
import cocotb
7-
8-
9-
# strings are not supported on Icarus (gh-2585) or GHDL (gh-2584)
10-
@cocotb.test(
11-
expect_error=AttributeError
12-
if cocotb.SIM_NAME.lower().startswith("icarus")
13-
else TypeError
14-
if cocotb.SIM_NAME.lower().startswith("ghdl")
15-
else ()
16-
)
17-
async def test_unicode_handle_assignment_deprecated(dut):
18-
with pytest.warns(DeprecationWarning, match=".*bytes.*"):
19-
dut.stream_in_string.value = "Bad idea"
20-
await cocotb.triggers.ReadWrite()
21-
22-
23-
@cocotb.test()
24-
async def test_convert_handle_to_string_deprecated(dut):
25-
dut.stream_in_data.value = 0
26-
await cocotb.triggers.Timer(1, units="ns")
27-
28-
with pytest.warns(FutureWarning, match=".*_path.*"):
29-
as_str = str(dut.stream_in_data)
30-
31-
# in future this will be ` == dut._path`
32-
assert as_str == str(dut.stream_in_data.value)
33-
34-
if cocotb.LANGUAGE == "verilog":
35-
# the `NUM_OF_MODULES` parameter is only present in the verilog design
36-
with pytest.warns(FutureWarning, match=".*_path.*"):
37-
as_str = str(dut.NUM_OF_MODULES)
38-
39-
# in future this will be ` == dut._path`
40-
assert as_str == str(dut.NUM_OF_MODULES.value)

0 commit comments

Comments
 (0)