From cd000bef2c476342d74fc2a042dacfb3c2945b21 Mon Sep 17 00:00:00 2001 From: Helmut Grohne Date: Tue, 3 Jun 2025 07:37:14 +0200 Subject: add method MountFlags.tonames It provides part of the functionality of MountFlags.tostr. --- linuxnamespaces/syscalls.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/linuxnamespaces/syscalls.py b/linuxnamespaces/syscalls.py index c4edad2..7f17c9f 100644 --- a/linuxnamespaces/syscalls.py +++ b/linuxnamespaces/syscalls.py @@ -256,22 +256,25 @@ class MountFlags(enum.IntFlag): reverse=True, ) - def tostr(self) -> str: - """Attempt to represent the flags in a comma-separated, textual way.""" + def tonames(self) -> list[str]: + """Represent the flags as a sequence of list of flag names.""" if (self & MountFlags.PROPAGATION_FLAGS).bit_count() > 1: raise ValueError("cannot represent conflicting propagation flags") parts: list[str] = [] remain = self for val, text in MountFlags.__flagvals: - # Older mypy think MountFlags.__flagvals and thus text was of type - # MountFlags. + # Older mypy wrongly deduces the type of MountFlags.__flagvals. assert isinstance(text, str) if remain & val == val: parts.insert(0, text) remain &= ~val if remain: raise ValueError("cannot represent flags {remain}") - return ",".join(parts) + return parts + + def tostr(self) -> str: + """Represent the flags in a comma-separated, textual way.""" + return ",".join(self.tonames()) class MountSetattrFlags(enum.IntFlag): -- cgit v1.2.3