Repository navigation
fix(protocols): make() rejects an enum member name given as str unless a namespace is passed - #1227
Merged
Merged
Conversation
Contributor
|
Coverage: 88.92% (unit tier, Python 3.14,
Per-file detail: the |
Owner
Author
|
Cross-review verdict on
|
…s a namespace is passed Protocol._make_index now infers the namespace for a str member name when none is given: it finds the calling make() method on the class, picks the arguments whose value equals the name, whose *_namespace companion is None, and whose default is an enum member, and uses that default's enum class. If several arguments match, every candidate enum must have the name with the same value; otherwise ProtocolNotImplemented asks for an explicit *_namespace. int, enum members and explicit namespaces take the same path as before. Arguments whose default is not an enum member (None defaults and loop variables over list arguments) keep the old behaviour. Closes #1210
JarryShaw
force-pushed
the
fix/1210-make-index-str
branch
from
October 7, 2026 18:08
bb5c9a8 to
d7c505f
Compare
Owner
Author
|
Cross-review verdict on
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
make pylint,make mypy,make isort) — ran pylint (Makefile flags), mypy and isort onprotocol.pyonly: no new findings in the changed regionmake testpasses, and a test case covers the change — the legs listed below, not the fullmake testWhat is the purpose of your pull request?
fix— corrects a defectDescription of your pull request and other information
Closes #1210
_make_indexnow infers the namespace when it gets astrand nonamespace. It finds the callingmake()/_make_*method on the class and picks the arguments whose value equals the name (==, not identity), whose<arg>_namespaceisNone, and whose default is an enum member. It then uses that default's enum class. When several arguments share the name, e.g.IPv4(tos_thr='HIGH', tos_rel='HIGH'), every candidate enum must have it with the same value. Otherwise it raisesProtocolNotImplemented: ... ambiguous member name ...; pass a_namespace= or b_namespace= explicitly, e.g.IPv4(tos_del='LOW', tos_thr='LOW'), sinceLOWis not aToSThroughputmember. No caller changed.int, enum members and explicit namespaces never reach the new code. 94 arguments across 20 modules are now inferable.Not inferable, so these keep the old behaviour:
HTTP.make(status=),HOPOPT/IPv6_Opts_make_opt_smf_dpd(tid_type=)and_make_opt_mpl(seed_type=), all of which default toNone. Also the list arguments of 12 HIP_make_param_*methods (dh_group_list,hip_transform,hip_cipher,nat_traversal_mode,hit_suite_list,transport_format_list,esp_transform,hip_transport_mode,reg_info/request/response/failed). Their items are passed through a loop variable, not through a parameter with an enum default.Before / after:
Ethernet(type='Internet_Protocol_version_6')raisedProtocolNotImplemented. It now gives…86dd, the same bytes as the enum member.L2TPv2(type='Control')now givesc002000800000000.Tests: new
tests/protocols/test_make_index_str_unit.pycovers link (Ethernet, L2TPv2), internet (IPv4), transport (TCP option), application (OSPF) and misc (PCAP header). Each case checks str == member == int, plus the non-default member. It also covers both ToS collisions and an ambiguous case, both a constructed one and the realLOWone. Againstmainit fails 8; against the first revision of this PR it fails the 2 collision tests; with the fix, 7 passed and 6 subtests passed.run_unittest_leg.py protocols --exclude protocols/internet: 857 tests, 0 failures, 0 errorsrun_unittest_leg.py protocols/internet: 503 tests, 0 failures, 0 errorspytest tests/project(first revision): 389 passed, 1 skipped