From 2f5a3cdc0393e9f9c04a2b83335405b4ef93653a Mon Sep 17 00:00:00 2001 From: nsheff Date: Wed, 17 May 2023 15:45:33 -0400 Subject: [PATCH 1/9] 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/9] 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/9] 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/9] 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/9] 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() From 80809329dbea21a50a417842590ee06a3d1d364a Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Mon, 29 May 2023 00:14:02 +0200 Subject: [PATCH 6/9] add numpy dependency for tests; close #79 --- requirements/requirements-test.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/requirements-test.txt b/requirements/requirements-test.txt index a1303c8..1e91f21 100644 --- a/requirements/requirements-test.txt +++ b/requirements/requirements-test.txt @@ -1,3 +1,4 @@ coveralls +numpy pytest>=4.6.9 pytest-cov>=2.8.1 From 852295c38f8845b37c3236a38f72661e16b380df Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Mon, 29 May 2023 00:14:36 +0200 Subject: [PATCH 7/9] try to fix 3.11 update to pickling-related attributes --- tests/test_AttMap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_AttMap.py b/tests/test_AttMap.py index b73c08a..076106a 100644 --- a/tests/test_AttMap.py +++ b/tests/test_AttMap.py @@ -2,6 +2,7 @@ import itertools import os +import sys import pickle import numpy as np @@ -379,7 +380,8 @@ def test_attribute_access(self, return_identity, attr_to_request, attrdict): elif attr_to_request in self.NORMAL_ITEM_ARG_VALUES: # Request for common protected function returns the function. assert callable(getattr(attrdict, attr_to_request)) - elif attr_to_request in self.PICKLE_ITEM_ARG_VALUES: + elif attr_to_request == "__getstate__" and sys.version_info < (3, 11) or attr_to_request == "__setstate__": + # See: https://stackoverflow.com/questions/74331573/pyomo-compatibility-with-python-3-11 # We don't tinker with the pickle-relevant attributes. with pytest.raises(AttributeError): print( From 2508927217a6c7c9d4fab77b167bef4362b00d80 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Mon, 29 May 2023 00:20:29 +0200 Subject: [PATCH 8/9] apply formatter --- setup.py | 2 +- tests/test_AttMap.py | 6 +++++- tests/test_basic_ops_dynamic.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 094d620..abe1bc2 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ def read_reqs(reqs_name): ], keywords="dict, map, mapping, dot, item, getitem, attr, getattr, key-value, dynamic, mutable, access", url="https://github.com/pepkit/{}/".format(PACKAGE), - author=u"Nathan Sheffield, Vince Reuter, Michal Stolarczyk", + author="Nathan Sheffield, Vince Reuter, Michal Stolarczyk", license="BSD2", include_package_data=True, test_suite="tests", diff --git a/tests/test_AttMap.py b/tests/test_AttMap.py index 076106a..205a45f 100644 --- a/tests/test_AttMap.py +++ b/tests/test_AttMap.py @@ -380,7 +380,11 @@ def test_attribute_access(self, return_identity, attr_to_request, attrdict): elif attr_to_request in self.NORMAL_ITEM_ARG_VALUES: # Request for common protected function returns the function. assert callable(getattr(attrdict, attr_to_request)) - elif attr_to_request == "__getstate__" and sys.version_info < (3, 11) or attr_to_request == "__setstate__": + elif ( + attr_to_request == "__getstate__" + and sys.version_info < (3, 11) + or attr_to_request == "__setstate__" + ): # See: https://stackoverflow.com/questions/74331573/pyomo-compatibility-with-python-3-11 # We don't tinker with the pickle-relevant attributes. with pytest.raises(AttributeError): diff --git a/tests/test_basic_ops_dynamic.py b/tests/test_basic_ops_dynamic.py index ab137eb..02a7889 100644 --- a/tests/test_basic_ops_dynamic.py +++ b/tests/test_basic_ops_dynamic.py @@ -29,7 +29,7 @@ def test_length_decrease(attmap_type, entries): def test_length_increase(attmap_type, entries): """Length/size of an attmap should match number of entries.""" m = get_att_map(attmap_type) - for (i, (k, v)) in enumerate(entries.items()): + for i, (k, v) in enumerate(entries.items()): assert i == len(m) m[k] = v assert (i + 1) == len(m) From fbb1cd203f40fb9bfe9290ef1bcc0666dd5a8d59 Mon Sep 17 00:00:00 2001 From: Vince Reuter Date: Mon, 29 May 2023 00:27:33 +0200 Subject: [PATCH 9/9] trigger CI pytest run --- .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 595a6e1..764aaef 100644 --- a/.github/workflows/run-pytest.yml +++ b/.github/workflows/run-pytest.yml @@ -2,7 +2,7 @@ name: Run pytests on: push: - branches: [dev] + branches: [dev, vr/fix-tests] pull_request: branches: [master]