On 18/10/2026 12:11, John Bokma wrote:
> On 18/10/2026 03:54, rbowman wrote:
>> On Sat, 17 Oct 2026 20:42:04 -0000 (UTC), Lawrence D’Oliveiro wrote: >>
>>> Who says you need to “declare dictionaries”? >>> >>>      l…@hypatia:~> python3 Python 3.14.7 (main, Sep 13 2026, 08:30:29) >>>      [GCC 16.2.0] on linux Type "help", "copyright", "credits" or >>>      "license" >>>      for more information. >>>      >>> a = "some text" print(a) >>>      some text >>>      >>> a = {"colour" : "green"} >>>      >>> print(a) >>>      {'colour': 'green'}
>> >> Python 3.14.4 (main, Aug 20 2026, 10:41:58) [GCC 15.2.0] on linux >> Type "help", "copyright", "credits" or "license" for more information.
>>>>> a = {"coluor" : "green"} >>>>> print(a)
>> {'coluor': 'green'}
>>>>> a["color"] = "purple" >>>>> print(a)
>> {'coluor': 'green', 'color': 'purple'} >> >> >> I've seen bugs introduced either by typos or a programmer who couldn't >> spell. It's either a very handy feature or a potential problem to add ad >> hoc fields.
> > If that's the case use a dataclass with frozen=True (and perhaps kw_only=True).
❯ python3 Python 3.14.7 (main, Aug 8 2026, 20:03:42) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> from dataclasses import dataclass >>> @dataclass(frozen=True, kw_only=True)
... class Config: ... color: str ...
>>> a = Config(color='purple') >>> a.coluor
Traceback (most recent call last): File "<python-input-3>", line 1, in <module> a.coluor AttributeError: 'Config' object has no attribute 'coluor'. Did you mean: 'color'?
>>> a.color = 'green'
Traceback (most recent call last): File "<python-input-4>", line 1, in <module> a.color = 'green' ^^^^^^^ File "<string>", line 15, in __setattr__ dataclasses.FrozenInstanceError: cannot assign to field 'color'
>>> a.color
'purple'
>>>
-- Static tumblelog generator: https://github.com/john-bokma/tumblelog/ Available as Python or Perl. Example tumblelog: https://plurrrr.com/