Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange DeprecationWarning behaviour in module struct #49448

Closed
hagen mannequin opened this issue Feb 10, 2009 · 5 comments
Closed

Strange DeprecationWarning behaviour in module struct #49448

hagen mannequin opened this issue Feb 10, 2009 · 5 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@hagen
Copy link
Mannequin

hagen mannequin commented Feb 10, 2009

BPO 5198
Nosy @birkenfeld, @mdickinson
Files
  • struct_warning.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-04-05.10:35:58.231>
    created_at = <Date 2009-02-10.07:14:28.555>
    labels = ['type-bug', 'library']
    title = 'Strange DeprecationWarning behaviour in module struct'
    updated_at = <Date 2010-04-06.15:23:14.621>
    user = 'https://bugs.python.org/hagen'

    bugs.python.org fields:

    activity = <Date 2010-04-06.15:23:14.621>
    actor = 'mark.dickinson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-04-05.10:35:58.231>
    closer = 'georg.brandl'
    components = ['Library (Lib)']
    creation = <Date 2009-02-10.07:14:28.555>
    creator = 'hagen'
    dependencies = []
    files = ['13007']
    hgrepos = []
    issue_num = 5198
    keywords = []
    message_count = 5.0
    messages = ['81532', '83159', '83206', '102367', '102469']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'isandler', 'mark.dickinson', 'hagen']
    pr_nums = []
    priority = 'normal'
    resolution = 'out of date'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue5198'
    versions = ['Python 2.6', 'Python 3.0']

    @hagen
    Copy link
    Mannequin Author

    hagen mannequin commented Feb 10, 2009

    struct.pack seems to raise a DeprecationWarning for some structure
    formats, but not for others:

    Python 2.6.1 (r261:67515, Dec  5 2008, 07:40:41) 
    [GCC 4.3.2] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import struct
    >>> struct.pack(">H", 1.0)
    sys:1: DeprecationWarning: integer argument expected, got float
    '\x00\x01'
    >>> struct.pack("H", 1.0)
    '\x01\x00'

    In addition the DeprecationWarning message gives a strange location for
    the problem. With the attached struct_warning.py it locates the problem
    at the function call foo() instead of the problematic call of struct.pack:

    $ python2.6 struct_warning.py 
    struct_warning.py:6: DeprecationWarning: integer argument expected, got
    float
      foo()

    @hagen hagen mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Feb 10, 2009
    @isandler
    Copy link
    Mannequin

    isandler mannequin commented Mar 4, 2009

    Here is another case, which I think is even worse.

    Range checks are done inconsistently as well:

    .../trunk> ./python -c 'import struct; struct.pack("B", 257)

    'Traceback (most recent call last):
      File "<string>", line 1, in <module>
    struct.error: ubyte format requires 0 <= number <= 255

    .../trunk> ./python -c 'import struct; struct.pack(">B", 257)'
    sys:1: DeprecationWarning: 'B' format requires 0 <= number <= 255

    @isandler
    Copy link
    Mannequin

    isandler mannequin commented Mar 5, 2009

    It appears that the different behavior results from trying to preserve
    backward compatibility with earlier version of Python

    see: http://bugs.python.org/issue1229380

    @birkenfeld
    Copy link
    Member

    Both examples now give consistent behavior independent of byteorder in trunk: packing floats with "H" works, packing bytes out of range with "B" raises.

    Closing as "out of date".

    @mdickinson
    Copy link
    Member

    The wrong location for the DeprecationWarnings was also fixed in trunk in r78690. I've backported the fix to release26-maint in r79834.

    I don't dare mess further with the warnings in a bugfix release; as Georg points out, the issues are fixed in trunk. BTW, one of the 2.6 issues (again fixed in trunk) that wasn't mentioned above is that some packs produce *two* overflow-related warnings:

    >>> import struct
    >>> struct.pack('<L', -1)
    __main__:1: DeprecationWarning: struct integer overflow masking is deprecated
    __main__:1: DeprecationWarning: 'L' format requires 0 <= number <= 4294967295
    '\xff\xff\xff\xff'

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants