@@ -31,7 +31,10 @@ class Method(EnumRegistry, StrEnum):
3131 legitimate members, and a new one is created through :meth:`register`,
3232 which can supply :attr:`safe` and :attr:`idempotent` where a bare wire
3333 method verb carries neither. ``get()`` matches ``key`` case-sensitively,
34- as :rfc:`9110` makes the method token (:issue:`896`).
34+ as :rfc:`9110` makes the method token (:issue:`896`), and checks it
35+ against member values as well as names (:issue:`908`). A member's
36+ :class:`str` payload is its value, so ``Method.GET == 'GET'``
37+ (:issue:`870`).
3538
3639 """
3740
@@ -199,21 +202,13 @@ def _unregistered_member(cls, value: 'str', name: 'str') -> 'Method':
199202 declared, never reformatted. Only :attr:`name` -- the
200203 identifier, not the value -- is canonicalised.
201204
202- A *registered* member of this class used to carry something
203- different here: GitHub issue :issue:`870` found that
204- :meth:`__new__` called ``str.__new__(cls)`` with no
205- argument at all, so every one of the 40 declared members'
206- own :class:`str` payload was permanently empty regardless
207- of ``value`` (``str(Method.GET) == ''``, and
208- ``Method.GET == 'GET'`` was :obj:`False`) -- true on
209- ``main`` at ``60b85e3a4`` as well as when this docstring
210- was first written. :issue:`870` fixed :meth:`__new__` to
211- ``str.__new__(cls, value)``, mirroring
205+ A *registered* member carries its value the same way:
206+ :meth:`__new__` passes ``value`` to ``str.__new__``, as
212207 :class:`~pcapkit.const.ftp.command.Command`'s own
213- ``__new__``, so a registered member's payload now agrees
214- with an *unregistered* member built through this method:
215- both carry their own value as real :class:`str` content
216- ( ``str(Method('frob')) == 'frob'``).
208+ ``__new__`` does (:issue:`870`) , so both kinds of member
209+ carry their own value as real :class:`str` content
210+ (``str(Method.GET) == 'GET'`` and
211+ ``str(Method('frob')) == 'frob'``).
217212 name: Bare label for the unregistered member -- here, the
218213 canonical upper-case form of ``value``, matching the name
219214 every *registered* member of this class is looked up by,
@@ -231,32 +226,31 @@ def get(cls, key: 'str', default: 'Optional[str]' = None) -> 'Method':
231226 """Backport support for original codes.
232227
233228 Delegates to :meth:`~pcapkit.corekit.enum.EnumLookup.get` for the
234- lookup itself, per GitHub issue :issue:`908`: the previous override checked
235- only ``_member_map_`` (names), never ``_value2member_map_``
236- (values), so the two IANA methods whose member *name* differs from
237- their *value* -- ``BASELINE_CONTROL`` / ``'BASELINE-CONTROL'`` and
229+ lookup itself, so ``key`` is checked against member values as well
230+ as names (GitHub issue :issue:`908`). That is what resolves the two
231+ IANA methods whose member *name* differs from their *value* --
232+ ``BASELINE_CONTROL`` / ``'BASELINE-CONTROL'`` and
238233 ``VERSION_CONTROL`` / ``'VERSION-CONTROL'``, a hyphen being unusable
239- in a Python identifier -- failed to resolve through ``get`` even
240- though :meth:`_missing_` (and so the constructor) already found
241- them via that same value-side lookup.
242-
243- The base is a :class:`classmethod`
244- (:meth:`~pcapkit.corekit.enum.EnumLookup.get`), and a zero-argument
245- ``super()`` needs a first argument to bind, so this override had to
246- move from :class:`staticmethod` to :class:`classmethod` to delegate
247- at all -- see GitHub issue :issue:`908`'s own correction of the fix it
248- originally proposed. Callers are unaffected by the switch itself:
249- ``Method.get('X')`` binds identically either way.
250-
251- ``default`` keeps its existing meaning here rather than adopting
252- the base's ``NO_DEFAULT`` sentinel and its value-only fallback --
253- widening it would be caller-visible, since the base's ``default``
254- must already name a *registered* value (resolved through
255- ``_value2member_map_``), while this override's ``default`` instead
256- supplies the *value* of a freshly minted unregistered member.
257- Nothing in this tree calls ``get`` with a non-``None`` ``default``
258- to notice today, but widening the signature is a separate change
259- from this defect and stays out of scope.
234+ in a Python identifier -- which :meth:`_missing_` (and so the
235+ constructor) also finds by value.
236+
237+ It is a :class:`classmethod`, as the base is, because a
238+ zero-argument ``super()`` needs a first argument to bind
239+ (:issue:`908`). ``Method.get('X')`` binds the same as it would on a
240+ :class:`staticmethod`.
241+
242+ ``default`` does not follow the base's ``NO_DEFAULT`` sentinel and
243+ value-only fallback: the base's ``default`` must name a
244+ *registered* value (resolved through ``_value2member_map_``), while
245+ this override's ``default`` supplies the *value* of the
246+ unregistered member it builds on a miss.
247+
248+ .. versionchanged:: 1.5.0
249+
250+ A non-:class:`str` ``key`` raises :exc:`ValueError`
251+ (:issue:`908`). ``get(42)`` and ``get(None)`` raised
252+ :exc:`AttributeError` from ``key.upper()``, and ``get(b'GET')``
253+ raised :exc:`TypeError`.
260254
261255 Args:
262256 key: Key to get enum item. Looked up case-**sensitively**,
@@ -267,26 +261,20 @@ def get(cls, key: 'str', default: 'Optional[str]' = None) -> 'Method':
267261 command codes are not. Checked against both member names
268262 and values, via the base's own precedence -- name before
269263 value -- so a value-only match such as
270- ``'BASELINE-CONTROL'`` now resolves too, closing GitHub
271- issue :issue:`908`.
264+ ``'BASELINE-CONTROL'`` resolves too (:issue:`908`).
272265 default: Value for the unregistered member built when ``key``
273266 matches neither a name nor a value. ``None``, the
274- default, uses ``key`` itself -- unchanged from before
275- GitHub issue :issue:`908`.
267+ default, uses ``key`` itself.
276268
277269 Raises:
278270 ValueError: If ``key`` is not a :class:`str`. This reaches the
279271 caller from the base's non-``str`` branch, which calls
280272 ``cls(key)`` and so ``_missing_``, and is **not** caught by
281273 the ``except KeyError`` fallback below -- only a failed
282- *name* lookup is. The non-``str`` surface therefore moved
283- with GitHub issue :issue:`908`: ``get(42)`` and ``get(None)`` used
284- to raise :exc:`AttributeError` from ``key.upper()``, and
285- ``get(b'GET')`` used to *return* a member whose name and
286- value were both the :class:`bytes` object. Raising is the
287- intended behaviour -- a ``bytes``-valued ``Method`` is not a
288- thing this registry should hand back -- but it is a change,
289- so it is stated rather than left to be discovered.
274+ *name* lookup is. Raising is the intended behaviour for
275+ ``get(b'GET')`` as well: a member whose name and
276+ value were both the :class:`bytes` object is not a thing
277+ this registry should hand back.
290278
291279 :meta private:
292280 """
0 commit comments