bitmask.py: move utility functions to util.py

This commit is contained in:
dogeystamp 2022-07-31 20:51:15 -04:00
parent 6d69ee3958
commit 456bc7b618
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 15 additions and 9 deletions

View File

@ -3,13 +3,7 @@
"""Utilities for manipulating bitmasks."""
def _fullname(obj):
"""Get the full class name of an object, including module.
Returns:
String with class name, which can be used in an `eval()`.
"""
return f"{obj.__class__.__qualname__}"
import bitmask.util as util
class Bitmask:
"""Generic bitmask, which represents multiple Enum values.
@ -103,13 +97,13 @@ class Bitmask:
return '|'.join([flag.name for flag in self]) or "0"
def __repr__(self):
enum_name = _fullname(self.AllFlags(0))
enum_name = util.fullname(self.AllFlags(0))
args = ', '.join(
[enum_name] +
[f"{enum_name}.{flag.name}" for flag in self]
)
return f"{_fullname(self)}({args})"
return f"{util.fullname(self)}({args})"
def __eq__(self, other):
"""Check equality."""

12
bitmask/util.py Normal file
View File

@ -0,0 +1,12 @@
# Copyright 2022 dogeystamp <dogeystamp@disroot.org>
# See LICENSE file for more details.
"""Miscellaneous utilities for formatting exceptions, etc."""
def fullname(obj):
"""Get the full class name of an object, including module.
Returns:
String with class name, which can be used in an `eval()`.
"""
return f"{obj.__class__.__qualname__}"