Skip to content

Commit 6d2ad2b

Browse files
l0lawrenceCopilot
andcommitted
fix(http-client-python): clarify _model_base.py mapping docstrings
Replace the ambiguous 'D' placeholder (inherited from CPython's MutableMapping ABC docstrings) in the generated _MyMutableMapping base class with plain-English descriptions. Fixes #11196 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 598c00f commit 6d2ad2b

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: fix
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Clarify docstrings in the generated `_MyMutableMapping` base class in `_model_base.py` so they no longer use the ambiguous `D` placeholder (e.g. `Remove all items from D.` is now `Remove all items from the dictionary.`)

‎packages/http-client-python/generator/pygen/codegen/templates/model_base.py.jinja2‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,21 +470,21 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
470470

471471
def keys(self) -> typing.KeysView[str]:
472472
"""
473-
:returns: a set-like object providing a view on D's keys
473+
:returns: a set-like object providing a view on the mapping's keys
474474
:rtype: ~typing.KeysView
475475
"""
476476
return self._data.keys()
477477

478478
def values(self) -> typing.ValuesView[typing.Any]:
479479
"""
480-
:returns: an object providing a view on D's values
480+
:returns: an object providing a view on the mapping's values
481481
:rtype: ~typing.ValuesView
482482
"""
483483
return self._data.values()
484484

485485
def items(self) -> typing.ItemsView[str, typing.Any]:
486486
"""
487-
:returns: set-like object providing a view on D's items
487+
:returns: a set-like object providing a view on the mapping's items
488488
:rtype: ~typing.ItemsView
489489
"""
490490
return self._data.items()
@@ -494,7 +494,7 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
494494
Get the value for key if key is in the dictionary, else default.
495495
:param str key: The key to look up.
496496
:param any default: The value to return if key is not in the dictionary. Defaults to None
497-
:returns: D[k] if k in D, else d.
497+
:returns: The value for key if key is in the dictionary, else default.
498498
:rtype: any
499499
"""
500500
try:
@@ -529,19 +529,19 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
529529
Removes and returns some (key, value) pair
530530
:returns: The (key, value) pair.
531531
:rtype: tuple
532-
:raises KeyError: if D is empty.
532+
:raises KeyError: if the dictionary is empty.
533533
"""
534534
return self._data.popitem()
535535

536536
def clear(self) -> None:
537537
"""
538-
Remove all items from D.
538+
Remove all items from the dictionary.
539539
"""
540540
self._data.clear()
541541

542542
def update(self, *args: typing.Any, **kwargs: typing.Any) -> None: # pylint: disable=arguments-differ
543543
"""
544-
Updates D from mapping/iterable E and F.
544+
Update the dictionary from a mapping or an iterable of key-value pairs.
545545
:param any args: Either a mapping object or an iterable of key-value pairs.
546546
"""
547547
self._data.update(*args, **kwargs)
@@ -554,10 +554,11 @@ class _MyMutableMapping(MutableMapping[str, typing.Any]):
554554

555555
def setdefault(self, key: str, default: typing.Any = _UNSET) -> typing.Any:
556556
"""
557-
Same as calling D.get(k, d), and setting D[k]=d if k not found
557+
Return the value for key if key is in the dictionary; otherwise set the key to
558+
default and return default.
558559
:param str key: The key to look up.
559560
:param any default: The value to set if key is not in the dictionary
560-
:returns: D[k] if k in D, else d.
561+
:returns: The value for key if key is in the dictionary, else default.
561562
:rtype: any
562563
"""
563564
if default is _UNSET:

0 commit comments

Comments
 (0)