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

Simplify time caching in DATE: header formatting (#2176) #2180

Merged
merged 2 commits into from
Oct 5, 2017
Merged

Simplify time caching in DATE: header formatting (#2176) #2180

merged 2 commits into from
Oct 5, 2017

Conversation

socketpair
Copy link
Contributor

@socketpair socketpair commented Aug 8, 2017

What do these changes do?

Are there changes in behavior for the user?

Related issue number

Issue #2176

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the changes folder
    • name it <issue_id>.<type> for example (588.bug)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

@socketpair
Copy link
Contributor Author

Will fix tests and formatting slightly later. Please review my idea.

if now != _cached_current_datetime:
# Weekday and month names for HTTP date/time formatting;
# always English!
# Tuples are contants stored in codeobject!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConStants

Copy link
Member

@fafhrd91 fafhrd91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets kill TimeService.


_cached_current_datetime = None
_cached_formatted_datetime = None
def get_formatted_datetime():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be helper method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean @staticmethod?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, classmethod

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just function in helpers.py

@asvetlov
Copy link
Member

asvetlov commented Aug 8, 2017

I have no strong opinion for the PR.
On one hand it simplifies the code, on other it adds global variable.
We have no globals yet and I very like it.
Adding tests might require mocking these global vars (which is not terrible bad but I like to avoid it).

@codecov-io
Copy link

codecov-io commented Aug 12, 2017

Codecov Report

Merging #2180 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #2180      +/-   ##
=========================================
+ Coverage   97.19%   97.2%   +<.01%     
=========================================
  Files          39      39              
  Lines        8227    8184      -43     
  Branches     1435    1433       -2     
=========================================
- Hits         7996    7955      -41     
+ Misses        102     101       -1     
+ Partials      129     128       -1
Impacted Files Coverage Δ
aiohttp/test_utils.py 98.59% <ø> (-0.03%) ⬇️
aiohttp/web.py 99.65% <ø> (ø) ⬆️
aiohttp/web_server.py 100% <ø> (ø) ⬆️
aiohttp/web_protocol.py 88.27% <100%> (+0.46%) ⬆️
aiohttp/web_response.py 98.71% <100%> (ø) ⬆️
aiohttp/helpers.py 97.26% <100%> (-0.17%) ⬇️
aiohttp/web_request.py 99.68% <100%> (-0.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 803510b...02f91cd. Read the comment docs.

@socketpair
Copy link
Contributor Author

socketpair commented Aug 12, 2017

Please wait. I'm writing test for correct caching in the new function.

@socketpair
Copy link
Contributor Author

And I have found and fixed significant bug (!) in my implementation.

@socketpair
Copy link
Contributor Author

Well, I consider this can be merged right now.

mock_gmtime.side_effect = gmtime

mock_time.return_value = 1234567890.998
assert helpers.rfc822_formatted_time() == 'Fri, 13 Feb 2009 23:31:30 GMT'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Friday 13 :)

@asvetlov
Copy link
Member

Ping

@socketpair
Copy link
Contributor Author

@asvetlov @fafhrd91

It seems this can be merged.

@@ -402,11 +400,6 @@ def keep_alive(self):
"""Is keepalive enabled by client?"""
return not self._message.should_close

@property
def time_service(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder if that would be a breaking change.

Copy link
Contributor Author

@socketpair socketpair Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine. As I remember time_service is not documented

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@socketpair Removing public attribute/method/property may break someone's code who depends on it.

@fafhrd91 Ah, cool then.

@socketpair socketpair merged commit 729eaff into aio-libs:master Oct 5, 2017
@socketpair socketpair deleted the time branch October 5, 2017 03:56
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants