commit:     382e5e19afa87443259c68de4a2dc73f5f6f715e
Author:     Brian Harring <ferringb <AT> gmail <DOT> com>
AuthorDate: Sun Nov 30 21:39:46 2025 +0000
Commit:     Brian Harring <ferringb <AT> gmail <DOT> com>
CommitDate: Sun Nov 30 21:39:46 2025 +0000
URL:        
https://gitweb.gentoo.org/proj/pkgcore/snakeoil.git/commit/?id=382e5e19

refactor(obj): drop popattr and unexport DelayedInstantation_kls

Signed-off-by: Brian Harring <ferringb <AT> gmail.com>

 src/snakeoil/cli/arghparse.py |  7 ++++---
 src/snakeoil/obj.py           | 13 +------------
 tests/test_obj.py             | 32 +-------------------------------
 3 files changed, 6 insertions(+), 46 deletions(-)

diff --git a/src/snakeoil/cli/arghparse.py b/src/snakeoil/cli/arghparse.py
index a964cbf..cd872f1 100644
--- a/src/snakeoil/cli/arghparse.py
+++ b/src/snakeoil/cli/arghparse.py
@@ -10,7 +10,6 @@ import pkgutil
 import subprocess
 import sys
 import traceback
-import types
 import typing
 from argparse import (
     _UNRECOGNIZED_ARGS_ATTR,
@@ -35,7 +34,7 @@ from snakeoil.formatters import PlainTextFormatter
 
 from .. import klass
 from ..mappings import ImmutableDict
-from ..obj import DelayedInstantiation, popattr
+from ..obj import DelayedInstantiation
 from ..sequences import split_elements, split_negations
 from ..strings import pluralism
 from ..version import get_version
@@ -643,7 +642,9 @@ class Namespace(argparse.Namespace):
     def pop(self, key, default=klass.sentinel):
         """Remove and return an object from the namespace if it exists."""
         try:
-            return popattr(self, key)
+            val = getattr(self, key)
+            delattr(self, key)
+            return val
         except AttributeError:
             if default is not klass.sentinel:
                 return default

diff --git a/src/snakeoil/obj.py b/src/snakeoil/obj.py
index 57d293b..392c1ee 100644
--- a/src/snakeoil/obj.py
+++ b/src/snakeoil/obj.py
@@ -73,7 +73,7 @@ If that doesn't make sense to the reader, it's probably best 
that the reader not
 try to proxy builtin objects like tuples, lists, dicts, sets, etc.
 """
 
-__all__ = ("DelayedInstantiation", "DelayedInstantiation_kls", "make_kls", 
"popattr")
+__all__ = ("DelayedInstantiation", "make_kls")
 
 import typing
 
@@ -109,17 +109,6 @@ if hasattr(object, "__sizeof__"):
 base_kls_descriptors = frozenset(base_kls_descriptors)
 
 
-def popattr(obj, name, default=klass.sentinel):
-    """Remove and return an attribute from an object if it exists."""
-    try:
-        return obj.__dict__.pop(name)
-    except KeyError:
-        if default is not klass.sentinel:
-            return default
-        # force AttributeError to be raised
-        getattr(obj, name)
-
-
 class BaseDelayedObject:
     """
     Base proxying object

diff --git a/tests/test_obj.py b/tests/test_obj.py
index 03a0338..cd0571f 100644
--- a/tests/test_obj.py
+++ b/tests/test_obj.py
@@ -1,4 +1,5 @@
 import pytest
+
 from snakeoil import obj
 
 # sorry, but the name is good, just too long for these tests
@@ -128,34 +129,3 @@ class TestDelayedInstantiation:
             "this is a class level attribute, thus shouldn't "
             "trigger instantiation"
         )
-
-
-class TestPopattr:
-    class Object:
-        pass
-
-    def setup_method(self, method):
-        self.o = self.Object()
-        self.o.test = 1
-
-    def test_no_attrs(self):
-        # object without any attrs
-        with pytest.raises(AttributeError):
-            obj.popattr(object(), "nonexistent")
-
-    def test_nonexistent_attr(self):
-        # object with attr trying to get nonexistent attr
-        with pytest.raises(AttributeError):
-            obj.popattr(self.o, "nonexistent")
-
-    def test_fallback(self):
-        # object with attr trying to get nonexistent attr using fallback
-        value = obj.popattr(self.o, "nonexistent", 2)
-        assert value == 2
-
-    def test_removed_attr(self):
-        value = obj.popattr(self.o, "test")
-        assert value == 1
-        # verify that attr was removed from the object
-        with pytest.raises(AttributeError):
-            obj.popattr(self.o, "test")

Reply via email to