Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_replace() no longer works on platform.uname_result objects #86329

Closed
cs-shadow mannequin opened this issue Oct 26, 2020 · 6 comments
Closed

_replace() no longer works on platform.uname_result objects #86329

cs-shadow mannequin opened this issue Oct 26, 2020 · 6 comments
Assignees
Labels
3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@cs-shadow
Copy link
Mannequin

cs-shadow mannequin commented Oct 26, 2020

BPO 42163
Nosy @malemburg, @jaraco, @cs-shadow
PRs
  • bpo-42163, bpo-42189, bpo-42659: Support uname_tuple._replace (for all but processor) #23010
  • [3.9] bpo-42163, bpo-42189, bpo-42659: Support uname_tuple._replace (GH-23010) #24232
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/jaraco'
    closed_at = <Date 2021-01-16.19:46:20.365>
    created_at = <Date 2020-10-26.22:21:52.802>
    labels = ['type-bug', 'library', '3.9', '3.10']
    title = '_replace() no longer works on platform.uname_result objects'
    updated_at = <Date 2021-01-16.19:46:20.365>
    user = 'https://github.com/cs-shadow'

    bugs.python.org fields:

    activity = <Date 2021-01-16.19:46:20.365>
    actor = 'jaraco'
    assignee = 'jaraco'
    closed = True
    closed_date = <Date 2021-01-16.19:46:20.365>
    closer = 'jaraco'
    components = ['Library (Lib)']
    creation = <Date 2020-10-26.22:21:52.802>
    creator = 'cs-shadow'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42163
    keywords = ['patch']
    message_count = 6.0
    messages = ['379694', '379756', '379854', '379872', '384129', '385146']
    nosy_count = 4.0
    nosy_names = ['lemburg', 'jaraco', 'cs-shadow', 'rocallahan']
    pr_nums = ['23010', '24232']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42163'
    versions = ['Python 3.9', 'Python 3.10']

    @cs-shadow
    Copy link
    Mannequin Author

    cs-shadow mannequin commented Oct 26, 2020

    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.

    @cs-shadow cs-shadow mannequin added 3.9 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Oct 26, 2020
    @jaraco
    Copy link
    Member

    jaraco commented Oct 27, 2020

    Indeed, it was unexpected that consumers of the uname_result were using _replace. In fact, the focus of the tests is on ensuring that users are able to access the items by index, e.g. uname()[0].

    It should be possible to support _replace on the uname_result as found in Python 3.9+. The real question is - is it important enough to declare and restore support for this use case based on this one report (and likely handful of other cases), or would it be better to discourage use of _replace for uname_result and provide a straightforward workaround (to be documented here) for those use-cases to employ?

    Marc, do you have an opinion?

    @jaraco jaraco added 3.10 only security fixes labels Oct 27, 2020
    @rocallahan
    Copy link
    Mannequin

    rocallahan mannequin commented Oct 29, 2020

    I filed bpo-42189, which is similar but maybe worse: copy.deepcopy() is broken for platform.uname_result objects.

    @jaraco
    Copy link
    Member

    jaraco commented Oct 29, 2020

    Please take a look at the PR. Let me know what you think about the limited compatibility it adds (still doesn't allow _replace on 'processor').

    @jaraco
    Copy link
    Member

    jaraco commented Dec 31, 2020

    New changeset a6fd0f4 by Jason R. Coombs in branch 'master':
    bpo-42163, bpo-42189, bpo-42659: Support uname_tuple._replace (for all but processor) (bpo-23010)
    a6fd0f4

    @jaraco
    Copy link
    Member

    jaraco commented Jan 16, 2021

    New changeset 799722c by Jason R. Coombs in branch '3.9':
    [3.9] bpo-42163, bpo-42189, bpo-42659: Support uname_tuple._replace (for all but processor) (GH-23010) (bpo-24232)
    799722c

    @jaraco jaraco closed this as completed Jan 16, 2021
    @jaraco jaraco closed this as completed Jan 16, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes 3.10 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant