New submission from Chandan Singh <chan...@chandansingh.net>:

Starting from Python 3.9, it seems like the `_replace()` method no longer  
works on `platform.uname_result` objects, that are returned by
`platform.uname()`. A simple example can be seen below, which works on Python 
3.8, but not on Python 3.9.

```
>>> import platform
>>> result = platform.uname()
>>> result._replace(machine="x86_64")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/collections/__init__.py", line 448, in _replace
    result = self._make(_map(kwds.pop, field_names, self))
  File "/usr/local/lib/python3.9/collections/__init__.py", line 441, in _make
    raise TypeError(f'Expected {num_fields} arguments, got {len(result)}')
TypeError: Expected 5 arguments, got 6
```

I'm not sure if this is an intended change or an uninteded side-effect. The 
`_replace` method does work on simple namedtuple objects, and `uname_result` 
claims to be:

> largely compatible with a simple namedtumple` object except that 'platform' 
> is resolved late and cached to avoid calling "uname" except when needed`

This late resolution is what's new in Python 3.9 and also the source of the 
issue  as far as I can tell. I suppose the answer may depend on how braod our 
definition of  "largely compatible" is.

For some context, we use `_replace` in the tests of our BuildStream project, 
which is why we ran into this. The fix is reasonably simple on our end by 
changing how we mock some bits. But I wanted to check here if it's considered a 
bug or not. For reference, this is the patch we neded on our end: 
https://gitlab.com/BuildStream/buildstream/-/merge_requests/2092.

----------
components: Library (Lib)
messages: 379694
nosy: cs-shadow
priority: normal
severity: normal
status: open
title: _replace() no longer works on platform.uname_result objects
type: behavior
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42163>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to