You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Incorrect warning when assign an unsigned integer member #114388
Assigning a negative value to an unsigned integer member can emit a RuntimeWarning.
$ ./python -Wa
>>> import _testcapi
>>> ts = _testcapi._test_structmembersType_NewAPI()
>>> ts.T_UBYTE=-42
<stdin>:1: RuntimeWarning: Truncation of value to unsigned char
>>> ts.T_USHORT=-42
<stdin>:1: RuntimeWarning: Truncation of value to unsigned short
>>> ts.T_UINT=-42
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
<stdin>:1: RuntimeWarning: Truncation of value to unsigned int
>>> ts.T_ULONG=-42
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
(And for T_ULONGLONG it raises an OverflowError, but this is perhaps another issue).
The first issue is that it emits two warnings for T_UINT. It is also weird that warnings are different.
The second issue is that if the value is not an int subclass, it emits a warning also for positive values for T_UINT and T_ULONG:
>>> classIndex:
... def__init__(self, value):
... self.value = value
... def__index__(self):
... returnself.value
...
>>> ts.T_UBYTE= Index(42)
>>> ts.T_USHORT= Index(42)
>>> ts.T_UINT= Index(42)
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
>>> ts.T_ULONG= Index(42)
<stdin>:1: RuntimeWarning: Writing negative value into unsigned field
(No warning is emitted for assigning a negative index to T_ULONGLONG, but this is perhaps another issue).
Activity
pythongh-114388: Fix warnings when assign an unsigned integer member
gh-114388: Fix warnings when assign an unsigned integer member (GH-11…
pythongh-114388: Fix an error in pythonGH-114391
[3.12] pythongh-114388: Fix warnings when assign an unsigned integer …
[3.11] pythongh-114388: Fix warnings when assign an unsigned integer …
gh-114388: Fix an error in GH-114391 (GH-115000)
[3.12] gh-114388: Fix warnings when assign an unsigned integer member (…
[3.11] gh-114388: Fix warnings when assign an unsigned integer member (…
pythongh-114388: Fix warnings when assign an unsigned integer member (p…
pythongh-114388: Fix an error in pythonGH-114391 (pythonGH-115000)
pythongh-114388: Fix warnings when assign an unsigned integer member (p…
pythongh-114388: Fix an error in pythonGH-114391 (pythonGH-115000)
encukou commentedon Mar 28, 2024
With this change, there's a new warning emitted for “Writing negative value into unsigned field”.
@zooba, you might be interested in this