From 2f5a3cdc0393e9f9c04a2b83335405b4ef93653a Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 17 May 2023 15:45:33 -0400 Subject: [PATCH 1/5] allow lower bound objects to retain attributes, not just items --- attmap/attmap.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/attmap/attmap.py b/attmap/attmap.py index 2346954..8249b96 100644 --- a/attmap/attmap.py +++ b/attmap/attmap.py @@ -109,7 +109,22 @@ def _metamorph_maplike(self, m): raise TypeError( "Cannot integrate a non-Mapping: {}\nType: {}".format(m, type(m)) ) - return self._lower_type_bound(m.items()) + to_return = self._lower_type_bound(m.items()) + + # Don't forget any attributes included in this item + for x in dir(m): + if x in m.items(): + continue + if x[:2] == "__": + continue + to_return.x = m.x + + return to_return + + + + + def _new_empty_basic_map(self): """Return the empty collection builder for Mapping type simplification.""" From 1bd49be9cd34839dff954f3d84a75f647796db55 Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 17 May 2023 16:58:20 -0400 Subject: [PATCH 2/5] update python versions --- .github/workflows/run-pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-pytest.yml b/.github/workflows/run-pytest.yml index 1fc5e3b..595a6e1 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [3.6, 3.9] + python-version: ["3.8", "3.11"] os: [ubuntu-latest] steps: From b2aacda4865217fa070ca6162e9e92004825c310 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 18 May 2023 07:24:24 -0400 Subject: [PATCH 3/5] some attr setting fixes (still not finished) --- attmap/attmap.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/attmap/attmap.py b/attmap/attmap.py index 8249b96..3eb4035 100644 --- a/attmap/attmap.py +++ b/attmap/attmap.py @@ -115,9 +115,9 @@ def _metamorph_maplike(self, m): for x in dir(m): if x in m.items(): continue - if x[:2] == "__": + if x[:1] == "_": continue - to_return.x = m.x + to_return.__setattr__(x, m.__getattribute__(x)) return to_return From ca76e7c211e98d783b25449e6de4a378ac24e855 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 18 May 2023 07:24:52 -0400 Subject: [PATCH 4/5] rename var --- attmap/attmap.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/attmap/attmap.py b/attmap/attmap.py index 3eb4035..2442b12 100644 --- a/attmap/attmap.py +++ b/attmap/attmap.py @@ -112,12 +112,12 @@ def _metamorph_maplike(self, m): to_return = self._lower_type_bound(m.items()) # Don't forget any attributes included in this item - for x in dir(m): - if x in m.items(): + for attr in dir(m): + if attr in m.items(): continue - if x[:1] == "_": + if attr[:1] == "_": continue - to_return.__setattr__(x, m.__getattribute__(x)) + to_return.__setattr__(attr, m.__getattribute__(attr)) return to_return From 6ca2f718dad142e8a49757a8408e90dcdc396145 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 18 May 2023 07:57:59 -0400 Subject: [PATCH 5/5] skip attrs for built-in types --- attmap/attmap.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/attmap/attmap.py b/attmap/attmap.py index 2442b12..0340ca0 100644 --- a/attmap/attmap.py +++ b/attmap/attmap.py @@ -111,21 +111,21 @@ def _metamorph_maplike(self, m): ) to_return = self._lower_type_bound(m.items()) - # Don't forget any attributes included in this item - for attr in dir(m): - if attr in m.items(): - continue - if attr[:1] == "_": - continue - to_return.__setattr__(attr, m.__getattribute__(attr)) + # Don't forget any attributes included in this item, for non-builtin items + if ( + m.__class__.__module__ != "builtins" + and m.__class__.__module__ != "collections" + ): + print(f"Class:{m.__class__.__module__}") + for attr in dir(m): + if attr in m.items(): + continue + if attr[:1] == "_": + continue + to_return.__setattr__(attr, m.__getattribute__(attr)) return to_return - - - - - def _new_empty_basic_map(self): """Return the empty collection builder for Mapping type simplification.""" return dict()