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

Large number of style-related changes to pass pylint #238

Merged
merged 2 commits into from
Oct 18, 2014

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Oct 13, 2014

This is not to be merged, but should be reviewed and scrutinized. /cc @silvolu @tseaver

This is upstream of #235 as that was motivated by this larger effort towards fixing #179 and #178.

As for review, we should particularly discuss the things I pointed out.

Some key things to notice:

  • The tools (pep8 / pylint) disagree about continutation lines.
    This is because PEP8 is ambiguous about "multi-line constructs".
    One of the examples for bracket indentation in the PEP is

    my_list = [
        1, 2, 3,
        4, 5, 6,
        ]

    but the PEP doesn't explicity say whether or not

    my_list = [1, 2, 3,
               4, 5, 6,
               ]

    would be allowed. As it turns out, pep8 (the tool) considers
    the latter to be a continuation while pylint does not.

  • I changed all indentation where this was a problem, but was
    intentionally inconsistent. This way we can see "all options"
    and discuss whichever is preferred.

  • I made a _MetadataMixin helper class for methods shared between
    storage.Bucket and storage.Key. I did not refactor the affected
    tests but they do still give 100% coverage.

  • To silence docstrings warnings I added many bogus docstrings
    without actually documenting the given objects.

  • I factored out part of

    storage.connection.Connection.generate_signed_url

    into a _get_expiration_seconds() method and added tests.
    This method is untested (has # pragma NO COVER) and is still very long.
    I refactored because pylint complained about too many locals.

  • I made sure tox -e lint and tox -e cover passed.

  • I increased the maximum number of arguments from 5 to 10 and
    the maximum public methods from 20 to 30. Offenders were:

    • storage.connection.Connection.make_request (6 arguments)
    • storage.connection.Connection.api_request (9 arguments)
    • storage.connection.Connection.generate_signed_url (6 arguments)
    • storage.bucket.Bucket (27 public methods) and
    • storage.key.Key (23 public methods)

    I think refactoring these should be considered (though is not
    mandatory). I certainly don't know a good solution for the class
    public methods.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

@tseaver I also forgot to mention that I needed a mock for datetime.datetime.utcnow in test__get_expiration_seconds (in storage/test_connection.py) .

I just did the first thing that came to mind, but it is a bit hacky. So

  1. Do we have a standard mocking approach / library that we want to use.
  2. Do you have any insights specific to mocking datetime. (It was kind of a pain.)

@tseaver
Copy link
Contributor

tseaver commented Oct 13, 2014

Hmm, tests are failing for me (maybe a timezone-related issue?):

py27 create: /home/tseaver/projects/agendaless/Google/src/gcloud-python/.tox/py27
py27 installdeps: nose, unittest2
py27 inst: /home/tseaver/projects/agendaless/Google/src/gcloud-python/.tox/dist/gcloud-0.02.2.zip
py27 runtests: PYTHONHASHSEED='3555183268'
py27 runtests: commands[0] | nosetests
.....................................................................................................................................................................................................................................................................................................FF..............................................................................................................
======================================================================
FAIL: test__get_expiration_seconds (gcloud.storage.test_connection.TestConnection)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/gcloud/storage/test_connection.py", line 526, in test__get_expiration_seconds
    CALL_FUT(expiration_no_tz))
AssertionError: 1092902400 != 1092891600

======================================================================
FAIL: test__get_expiration_seconds_w_timedelta (gcloud.storage.test_connection.TestConnection)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tseaver/projects/agendaless/Google/src/gcloud-python/gcloud/storage/test_connection.py", line 583, in test__get_expiration_seconds_w_timedelta
    CALL_FUT(expiration_as_delta))
AssertionError: 1092902400 != 1092891600

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

@tseaver I think I don't understand the expected behavior well enough. You'll notice the difference is 3 hours, the difference between our local time zones. This must mean the relevant code

expiration.replace(tzinfo=pytz.utc)

is actually assuming the datetime.datetime object has the local timezone?

@@ -257,8 +278,7 @@ def upload_file(self, filename, key=None):
key = self.new_key(key)
return key.set_contents_from_filename(filename)

def upload_file_object(self, fh, key=None):
# TODO: What do we do about overwriting data?
def upload_file_object(self, file_obj, key=None):

This comment was marked as spam.

@tseaver
Copy link
Contributor

tseaver commented Oct 13, 2014

WRT mocking datetime, I've done the following (e.g., at module scope of the MUT):

_UTCNOW = None # unit tests can replace
def _utcnow(): #pragma NO COVERAGE
    if _UTCNOW is not None:
        return _UTCNOW
    return datetime.datetime.utcnow()

Later in the module, replace 'datetime.datetime.utcnow()' with '_utcnow()'.

and then in a test:

def test_foo(self):
    import datetime
    from gcloud import credentials as MUT

    utcnow = datetime.datetime.utcnow()
    with _Monkey(MUT, _UTCNOW=utcnow):
        result = self._callFUT(1000)
    self.assertEqual(result, utcnow + datetime.timedelta(0, 1000)

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

Rebased to master after #235 was merged.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

@tseaver Since datetime.datetime is not a pure Python class, the attributes can't be patched.

>>> import datetime
>>> datetime.datetime.utcnow = None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't set attributes of built-in/extension type 'datetime.datetime'

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

BTW @tseaver this PR can't be merged until we resolve the discussion, so the rebase is not so important.

Here are the datastore docstrings for you to handle:
https://gist.github.com/dhermes/ab246529ad1e2ae0b9bf

These are the rest, I will tackle:
https://gist.github.com/dhermes/a52007c58557419a310d

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

Found the issue and it wasn't with datetime. I'm happy we tested this because time.mktime computes a local time, which the method goes out of it's way to avoid. See StackOverflow for details.

@tseaver
Copy link
Contributor

tseaver commented Oct 13, 2014

@dhermes I wasn't suggesting patching the 'datetime.datetime' class: I was patching the 'gcloud.credentials' module.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 111ce66 on dhermes:large-style-changes into 61232de on GoogleCloudPlatform:master.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

@tseaver I see now, sorry I read too quickly.

@dhermes
Copy link
Contributor Author

dhermes commented Oct 13, 2014

NOTE: I just rebased on top of #241

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling af1d5d7 on dhermes:large-style-changes into 61232de on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling af1d5d7 on dhermes:large-style-changes into 61232de on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 936ff32 on dhermes:large-style-changes into 61232de on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 9fa9d90 on dhermes:large-style-changes into 61232de on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling 76a8d05 on dhermes:large-style-changes into 11c8765 on GoogleCloudPlatform:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same when pulling f2bef6e on dhermes:large-style-changes into fba037f on GoogleCloudPlatform:master.

parthea pushed a commit that referenced this pull request Jun 4, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Jun 4, 2023
* feat: add support for python 3.10

* ci: opt in to use multiple projects
parthea pushed a commit that referenced this pull request Jun 4, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Jun 4, 2023
* ci(python): run lint / unit tests / docs as GH actions

Source-Link: googleapis/synthtool@57be0cd
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:ed1f9983d5a935a89fe8085e8bb97d94e41015252c5b6c9771257cf8624367e6

* add commit to trigger gh actions

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea added a commit that referenced this pull request Jul 6, 2023
* chore(deps): update all dependencies

* revert numpy update for python_version <= '3.6'

* pin numpy 1.21.4 for python 3.7 samples

* fix typo

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea pushed a commit that referenced this pull request Jul 6, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/26c7505b2f76981ec1707b851e1595c8c06e90fc
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f946c75373c2b0040e8e318c5e85d0cf46bc6e61d0a01f3ef94d8de974ac6790
parthea added a commit that referenced this pull request Aug 15, 2023
* chore(python): use cov_level in unittest gh action

Source-Link: googleapis/synthtool@e5aaa84
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:d22cd2ddce65fdac6986f115563faf2fc81482b09dfbea83ac2808c92ecfdff0

* set coverage to 100%

* 🦉 Updates from OwlBot

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

* 🦉 Updates from OwlBot

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>
Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea pushed a commit that referenced this pull request Sep 14, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/92006bb3cdc84677aa93c7f5235424ec2b157146
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:2e247c7bf5154df7f98cce087a20ca7605e236340c7d6d1a14447e5c06791bd6
parthea pushed a commit that referenced this pull request Sep 22, 2023
🤖 I have created a release *beep* *boop*
---


## [1.7.0](googleapis/python-bigquery-connection@v1.6.0...v1.7.0) (2022-08-02)


### Features

* Add service_account_id output field to CloudSQL properties ([#237](googleapis/python-bigquery-connection#237)) ([adc73a6](googleapis/python-bigquery-connection@adc73a6))


### Documentation

* deprecate the AwsCrossAccountRole property ([#240](googleapis/python-bigquery-connection#240)) ([ad17197](googleapis/python-bigquery-connection@ad17197))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
parthea pushed a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@453a5d9
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:81ed5ecdfc7cac5b699ba4537376f3563f6f04122c4ec9e735d3b3dc1d43dd32
parthea pushed a commit that referenced this pull request Sep 22, 2023
parthea pushed a commit that referenced this pull request Sep 22, 2023
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-dlp/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)

Fixes #238  🦕
parthea pushed a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@56da63e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:993a058718e84a82fda04c3177e58f0a43281a996c7c395e0a56ccc4d6d210d7
parthea pushed a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@4760d8d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f0e4b51deef56bed74d3e2359c583fc104a8d6367da3984fc5c66938db738828

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Sep 22, 2023
* chore: delete owlbot.py

* 🦉 Updates from OwlBot

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>
parthea pushed a commit that referenced this pull request Oct 21, 2023
* fix: Add async context manager return types

chore: Mock return_value should not populate oneof message fields

chore: Support snippet generation for services that only support REST transport

chore: Update gapic-generator-python to v1.11.0
PiperOrigin-RevId: 545430278

Source-Link: googleapis/googleapis@601b532

Source-Link: googleapis/googleapis-gen@b3f18d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjNmMThkMGY2NTYwYTg1NTAyMmZkMDU4ODY1ZTc2MjA0NzlkN2FmOSJ9

* 🦉 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>
parthea pushed a commit that referenced this pull request Oct 21, 2023
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [google-cloud-asset](https://github.com/googleapis/python-asset) | `==3.2.0` -> `==3.2.1` | [![age](https://badges.renovateapi.com/packages/pypi/google-cloud-asset/3.2.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/pypi/google-cloud-asset/3.2.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/pypi/google-cloud-asset/3.2.1/compatibility-slim/3.2.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/pypi/google-cloud-asset/3.2.1/confidence-slim/3.2.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/python-asset</summary>

### [`v3.2.1`](https://github.com/googleapis/python-asset/blob/master/CHANGELOG.md#&#8203;321-httpswwwgithubcomgoogleapispython-assetcomparev320v321-2021-07-21)

[Compare Source](https://github.com/googleapis/python-asset/compare/v3.2.0...v3.2.1)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/python-asset).
parthea added a commit that referenced this pull request Oct 21, 2023
….0 (#238)

Co-authored-by: Anthonios Partheniou <partheniou@google.com>
parthea pushed a commit that referenced this pull request Oct 21, 2023
Source-Link: googleapis/synthtool@453a5d9
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:81ed5ecdfc7cac5b699ba4537376f3563f6f04122c4ec9e735d3b3dc1d43dd32
parthea pushed a commit that referenced this pull request Oct 22, 2023
Source-Link: https://github.com/googleapis/synthtool/commit/30bd01b4ab78bf1b2a425816e15b3e7e090993dd
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:9bc5fa3b62b091f60614c08a7fb4fd1d3e1678e326f34dd66ce1eefb5dc3267b
parthea pushed a commit that referenced this pull request Oct 22, 2023
* feat: Add VULNERABILITY_ASSESSMENT Note type to grafeas v1 API, adds Vex_Assessment derived from the Note to resources' occurrences, VEX notes now be written to add CVE assessments

PiperOrigin-RevId: 515727862

Source-Link: googleapis/googleapis@a4e6205

Source-Link: googleapis/googleapis-gen@3bc42dc
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiM2JjNDJkY2EyOTAwODE1YzE2NWNmN2QzNDE5ZmY3MGRmMDVkZmI5MCJ9

* 🦉 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>
parthea pushed a commit that referenced this pull request Oct 22, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Oct 22, 2023
Source-Link: googleapis/synthtool@050953d
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:65e656411895bff71cffcae97246966460160028f253c2e45b7a25d805a5b142

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Oct 31, 2023
…cp/templates/python_library/.kokoro (#238)

Source-Link: googleapis/synthtool@b4fe62e
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:3bf87e47c2173d7eed42714589dc4da2c07c3268610f1e47f8e1a30decbfc7f1

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants