Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding lazy loading support for dataset ID. #667

Merged
merged 3 commits into from
Feb 19, 2015

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Feb 19, 2015

NOTE: Has #666 as diffbase.

Still need to support connection (and eventually do the same
in storage).

Again verified only the lazy loading tests used implicit
behavior via

diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py
index 6e61636..6d67be6 100644
--- a/gcloud/datastore/_implicit_environ.py
+++ b/gcloud/datastore/_implicit_environ.py
@@ -177,6 +177,10 @@ class _LazyProperty(object):
         self._method = method

     def __get__(self, obj, objtype):
+        class FooError(Exception):
+            pass
+        raise FooError
+
         if obj is None or objtype is not _DefaultsContainer:
             return self

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 19, 2015
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 4ce0753 on dhermes:lazy-loading-attempt-4 into 72b6359 on GoogleCloudPlatform:master.

@dhermes
Copy link
Contributor Author

dhermes commented Feb 19, 2015

@tseaver I encountered your favorite, pylint made me change my code.

I first made a decorator

def _lazy_property_deco(method):
    return _LazyProperty(method.__name__, method)

class _DefaultsContainer(object):
    @_lazy_property_deco
    def dataset_id():
        return _determine_default_dataset_id()

but pylint complained of method-hidden (E0202):

Used when a class defines a method which is hidden by an instance
attribute from an ancestor class or set by some client code.

Essentially the decorator might put something different in the class definition than the code indicates.

If you prefer this approach we can add method-hidden to [MESSAGES CONTROL].disable in pylintrc_default.

I kind of like / dislike that pylint is trying to protect me from defining behavior I didn't mean to.

@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Feb 19, 2015
@tseaver
Copy link
Contributor

tseaver commented Feb 19, 2015

Shadowing a method with an instance attribute is a perfectly normal, acceptable practice: claiming it is wrong is insisting we ride the Python bike with training wheels on. Let's disable the warning.

Still need to support connection (and eventually do the same
in storage).

Again verified only the lazy loading tests used implicit
behavior via

```diff
diff --git a/gcloud/datastore/_implicit_environ.py b/gcloud/datastore/_implicit_environ.py
index 6e61636..6d67be6 100644
--- a/gcloud/datastore/_implicit_environ.py
+++ b/gcloud/datastore/_implicit_environ.py
@@ -177,6 +177,10 @@ class _LazyProperty(object):
         self._method = method

     def __get__(self, obj, objtype):
+        class FooError(Exception):
+            pass
+        raise FooError
+
         if obj is None or objtype is not _DefaultsContainer:
             return self
```
The _DATASET_ENV_VAR_NAME moved from datastore.__init__ to
datastore._implicit_environ.
- Ignoring method-hidden (PyLint) so we can decorate methods in a class.
- Making _lazy_property_deco(deferred_callable) to decorate and re-use
  the function name and use it as a callable
- Had to hack around Python2.6 differences in `staticmethod`
@dhermes
Copy link
Contributor Author

dhermes commented Feb 19, 2015

@tseaver PTAL. I just rebased this on top of #666.

Some things which differ than the original PR:

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling b9d96ed on dhermes:lazy-loading-attempt-4 into * on GoogleCloudPlatform:master*.

@tseaver
Copy link
Contributor

tseaver commented Feb 19, 2015

LGTM.

dhermes added a commit that referenced this pull request Feb 19, 2015
Adding lazy loading support for dataset ID.
@dhermes dhermes merged commit 56f60bb into googleapis:master Feb 19, 2015
@dhermes dhermes deleted the lazy-loading-attempt-4 branch February 19, 2015 20:56
vchudnov-g pushed a commit that referenced this pull request Sep 20, 2023
* feat: added baseline model version used to generate the summary
feat: added the platform of the virtual agent response messages

PiperOrigin-RevId: 556882279

Source-Link: googleapis/googleapis@c8eccda

Source-Link: googleapis/googleapis-gen@754eb33
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNzU0ZWIzMzQwZDc2ZTZkYTY5ZjA4MTA0MWQ5N2YwMTgwMjJhNTVkYSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the Datastore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants