From 456bc7b618779b4f12d781645583dce68a952342 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 31 Jul 2022 20:51:15 -0400 Subject: [PATCH] bitmask.py: move utility functions to util.py --- bitmask/bitmask.py | 12 +++--------- bitmask/util.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 bitmask/util.py diff --git a/bitmask/bitmask.py b/bitmask/bitmask.py index 7173d99..32dcb35 100644 --- a/bitmask/bitmask.py +++ b/bitmask/bitmask.py @@ -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.""" diff --git a/bitmask/util.py b/bitmask/util.py new file mode 100644 index 0000000..ec44b9a --- /dev/null +++ b/bitmask/util.py @@ -0,0 +1,12 @@ +# Copyright 2022 dogeystamp +# 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__}"