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
Change some implementation details in struct.Struct #145850
struct.Struct() accepts format as a string or a bytes object. It stores the format as the bytes object, but the format getter returns a string (see bpo-21071/gh-65270). While not yet initialized, it stores None, since gh-78724 the getter raises RuntimeError in such case (it returned None prior to gh-65270 and crashed prior to gh-78724). The getter could also raise an UnicodeDecodeError prior to gh-145743.
This all is a Python 2 legacy. We can simply store format as a string, this will simplify the getter. We can also use NULL instead of None as the default value, and use read-only members instead of a getter. This will make the code more strightforward.
This will have user visible effects:
Non-ASCII string format will lead to ValueError (or better use struct.error?) instead of UnicodeEncodeError.
Non-ASCII bytes format will lead to UnicodeDecodeError ValueError instead of struct.error.
Getting the format attribute of uninitialized Struct will lead to AttributeError instead of RuntimeError.
These cases normally do not occur in the user code, and the current exceptions is simply an implementation detail.
Activity
pythongh-145850: Change some implementation details in struct.Struct
gh-145850: Change some implementation details in struct.Struct (GH-14…
pythongh-145850: Change some implementation details in struct.Struct (p…