diff options
author | Helmut Grohne <helmut@subdivi.de> | 2025-08-13 10:35:05 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2025-08-13 10:35:05 +0200 |
commit | 60a8ec7dc195df0a98492d96e954b35fcd9d1eab (patch) | |
tree | c82caed086a6b9c61a9da7aee7dcebc9e94e8e52 | |
parent | 58a50ba141208d6b558c33bbda22c29aa515fbcf (diff) | |
download | python-linuxnamespaces-60a8ec7dc195df0a98492d96e954b35fcd9d1eab.tar.gz |
use typing.Self
Hence some staticmethods become classmethods to actually return an
instance of the class they're being called on.
-rw-r--r-- | linuxnamespaces/syscalls.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/linuxnamespaces/syscalls.py b/linuxnamespaces/syscalls.py index 667c557..abddffc 100644 --- a/linuxnamespaces/syscalls.py +++ b/linuxnamespaces/syscalls.py @@ -187,7 +187,7 @@ class MountFlags(enum.IntFlag): "unbindable": (UNBINDABLE, False, False), } - def change(self, flagsstr: str) -> "MountFlags": + def change(self, flagsstr: str) -> typing.Self: """Return modified mount flags after applying comma-separated mount flags represented as a str. Raise a ValueError if any given flag does not correspond to a textual mount flag. @@ -215,13 +215,13 @@ class MountFlags(enum.IntFlag): ret |= flag return ret - @staticmethod - def fromstr(flagsstr: str) -> "MountFlags": + @classmethod + def fromstr(cls, flagsstr: str) -> typing.Self: """Construct mount flags by changing flags according to the passed flagsstr using the change method on an initial value with all flags cleared. """ - return MountFlags.NONE.change(flagsstr) + return cls.NONE.change(flagsstr) __flagvals: list[tuple[int, str]] = sorted( [ @@ -286,15 +286,15 @@ class MountSetattrFlags(enum.IntFlag): AT_EMPTY_PATH = 0x1000 AT_RECURSIVE = 0x8000 - @staticmethod - def from_atflags(flags: AtFlags) -> "MountSetattrFlags": - ret = MountSetattrFlags.NONE + @classmethod + def from_atflags(cls, flags: AtFlags) -> typing.Self: + ret = cls.NONE if flags & AtFlags.AT_SYMLINK_NOFOLLOW: - ret |= MountSetattrFlags.AT_SYMLINK_NOFOLLOW + ret |= cls.AT_SYMLINK_NOFOLLOW if flags & AtFlags.AT_NO_AUTOMOUNT: - ret |= MountSetattrFlags.AT_NO_AUTOMOUNT + ret |= cls.AT_NO_AUTOMOUNT if flags & AtFlags.AT_EMPTY_PATH: - ret |= MountSetattrFlags.AT_EMPTY_PATH + ret |= cls.AT_EMPTY_PATH return ret @@ -470,7 +470,7 @@ class CapabilitySets: ) @classmethod - def get(cls, pid: int = 0) -> "CapabilitySets": + def get(cls, pid: int = 0) -> typing.Self: """Call capget to retrieve the current capability sets.""" header = cls._create_header(pid) data = (ctypes.c_uint32 * 6)() |