Repository: googleapis/google-cloud-python

Issue:
Remove `Property._CREATION_COUNTER` from `ndb`
Stepping into the [original source][1], it's clear it was not used for anything:

```
$ cd datastore-ndb-python/
$ git grep -n '_creation_counter'
RELEASE_NOTES:112:- Issue 175: Add _creation_counter.
ndb/model.py:888:  __creation_counter_global = 0
ndb/model.py:942:    Property.__creation_counter_global += 1
ndb/model.py:943:    self._creation_counter = Property.__creation_counter_global
ndb/model_test.py:1230:    self.assertTrue(MyModel.foo._creation_counter <
ndb/model_test.py:1231:                    MyModel.bar._creation_counter <
ndb/model_test.py:1232:                    MyModel.baz._creation_counter)
```

It seems the stated goal in https://github.com/GoogleCloudPlatform/datastore-ndb-python/issues/175 (when this was introduced) was never implemented.

@tseaver @chrisrossi WDYT?

@theacodes Do we have leeway to get rid of such a feature?

[1]: https://github.com/GoogleCloudPlatform/datastore-ndb-python


Discussion:
#144 adds 100% unit test coverage to all modules in gcloud.storage.


Resolving patch:
diff --git a/ndb/src/google/cloud/ndb/model.py b/ndb/src/google/cloud/ndb/model.py
--- a/ndb/src/google/cloud/ndb/model.py
+++ b/ndb/src/google/cloud/ndb/model.py
@@ -348,7 +348,6 @@ class Property(ModelAttribute):
     _verbose_name = None
     _write_empty_list = False
     # Non-public class attributes.
-    _CREATION_COUNTER = 0
     _FIND_METHODS_CACHE = {}
 
     def __init__(
@@ -385,9 +384,6 @@ def __init__(
             self._verbose_name = verbose_name
         if write_empty_list is not None:
             self._write_empty_list = write_empty_list
-        # Keep a unique creation counter. Note that this is not threadsafe.
-        Property._CREATION_COUNTER += 1
-        self._creation_counter = Property._CREATION_COUNTER
 
     @staticmethod
     def _verify_name(name):


Test patch:
diff --git a/ndb/tests/unit/test_model.py b/ndb/tests/unit/test_model.py
--- a/ndb/tests/unit/test_model.py
+++ b/ndb/tests/unit/test_model.py
@@ -330,25 +330,12 @@ def test___hash__():
             hash(wrapped)
 
 
-@pytest.fixture
-def zero_prop_counter():
-    counter_val = model.Property._CREATION_COUNTER
-    model.Property._CREATION_COUNTER = 0
-    try:
-        yield
-    finally:
-        model.Property._CREATION_COUNTER = counter_val
-
-
 class TestProperty:
     @staticmethod
-    def test_constructor_defaults(zero_prop_counter):
+    def test_constructor_defaults():
         prop = model.Property()
-        # Check that the creation counter was updated.
-        assert model.Property._CREATION_COUNTER == 1
-        assert prop._creation_counter == 1
         # Check that none of the constructor defaults were used.
-        assert prop.__dict__ == {"_creation_counter": 1}
+        assert prop.__dict__ == {}
 
     @staticmethod
     def _example_validator(prop, value):
@@ -360,7 +347,7 @@ def test__example_validator(self):
         assert validated == "abcde"
         assert self._example_validator(None, validated) == "abcde"
 
-    def test_constructor_explicit(self, zero_prop_counter):
+    def test_constructor_explicit(self):
         prop = model.Property(
             name="val",
             indexed=False,
@@ -381,43 +368,32 @@ def test_constructor_explicit(self, zero_prop_counter):
         assert prop._validator is self._example_validator
         assert prop._verbose_name == "VALUE FOR READING"
         assert not prop._write_empty_list
-        # Check that the creation counter was updated.
-        assert model.Property._CREATION_COUNTER == 1
-        assert prop._creation_counter == 1
 
     @staticmethod
-    def test_constructor_invalid_name(zero_prop_counter):
+    def test_constructor_invalid_name():
         with pytest.raises(TypeError):
             model.Property(name=["not", "a", "string"])
         with pytest.raises(ValueError):
             model.Property(name="has.a.dot")
-        # Check that the creation counter was not updated.
-        assert model.Property._CREATION_COUNTER == 0
 
     @staticmethod
-    def test_constructor_repeated_not_allowed(zero_prop_counter):
+    def test_constructor_repeated_not_allowed():
         with pytest.raises(ValueError):
             model.Property(name="a", repeated=True, required=True)
         with pytest.raises(ValueError):
             model.Property(name="b", repeated=True, default="zim")
-        # Check that the creation counter was not updated.
-        assert model.Property._CREATION_COUNTER == 0
 
     @staticmethod
-    def test_constructor_invalid_choices(zero_prop_counter):
+    def test_constructor_invalid_choices():
         with pytest.raises(TypeError):
             model.Property(name="a", choices={"wrong": "container"})
-        # Check that the creation counter was not updated.
-        assert model.Property._CREATION_COUNTER == 0
 
     @staticmethod
-    def test_constructor_invalid_validator(zero_prop_counter):
+    def test_constructor_invalid_validator():
         with pytest.raises(TypeError):
             model.Property(
                 name="a", validator=unittest.mock.sentinel.validator
             )
-        # Check that the creation counter was not updated.
-        assert model.Property._CREATION_COUNTER == 0
 
     def test_repr(self):
         prop = model.Property(