-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
PyStructSequence constructor ignores unknown field names #110235
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
Comments
The original code was added by @mwhudson in bpo-526072 (#36205, ce358e3). Because it was only for pickling support, omitting some validity checks was acceptable. |
@XuehaiPan, it may be interesting to you, since you already do something similar in the The difference is that this code cannot modify the input dict, because it is not kwargs. But it can count the found names. |
Any thoughts on allowing the present visible fields in PyStructSequence.__new__(cls: Self, sequence: Iterable[Any], dict: dict[str, Any]) -> Self Since we need For namedtuple.__new__(cls: Self, *args: Any, **kwargs: Any) -> Self >>> import collections
>>> MyTuple = collections.namedtuple('MyTuple', ['a', 'b', 'c', 'd'])
>>> MyTuple(1, 2, 3, 4, a=5, b=6)
TypeError: MyTuple.__new__() got multiple values for argument 'a' |
I opened a PR to resolve this. |
…quence constructor (GH-110258)
…ructSequence constructor (pythonGH-110258)
Bug report
PyStructSequence constructor takes two arguments: tuple and dict. The tuple specifies values for "visible" fields (i.e. what you get when interpret PyStructSequence as a tuple), the dict specifies values for fields that are accessible only by name (they are like
__slot__
attributes).The problem is that all invalid names are silently ignored. It includes names of "visible" fields and typos.
Linked PRs
TypeError
for duplicate/unknown fields in PyStructSequence constructor #110258The text was updated successfully, but these errors were encountered: