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

Fix syntax error under Python 3.7 for async param #966

Merged
merged 14 commits into from
Jul 16, 2018

Conversation

lopuhin
Copy link
Contributor

@lopuhin lopuhin commented Feb 26, 2018

Syntax error under Python 3.7 fixed for twisted.conch.manhole and twisted.main.imap4. async_ keyword argument is used by default instead of async, but async is also supported for backwards compatibility.

Twisted issue: https://twistedmatrix.com/trac/ticket/9384

@codecov
Copy link

codecov bot commented Feb 26, 2018

Codecov Report

Merging #966 into trunk will decrease coverage by 0.24%.
The diff coverage is 94.59%.

@@            Coverage Diff             @@
##            trunk     #966      +/-   ##
==========================================
- Coverage    91.9%   91.66%   -0.25%     
==========================================
  Files         844      843       -1     
  Lines      150622   149360    -1262     
  Branches    13143    13079      -64     
==========================================
- Hits       138436   136911    -1525     
- Misses      10098    10333     +235     
- Partials     2088     2116      +28

Accept async_ param instead of async, but also support passing async for
backwards compatibility.
@lopuhin
Copy link
Contributor Author

lopuhin commented Feb 27, 2018

One build failed due to Invalid argument name "async_" (https://travis-ci.org/twisted/twisted/jobs/346467875#L537) - probably it does not like a trailing underscore. AFAIK async_ is a commonly used way to replace async argument, but I can change it to something like is_async as well - what would be better?

@rodrigc
Copy link
Contributor

rodrigc commented Feb 27, 2018

Try using _async for the variable and getAsyncParam() for the function. The https://github.com/twisted/twistedchecker program seems to accept that.

@lopuhin
Copy link
Contributor Author

lopuhin commented Feb 27, 2018

Try using _async for the variable and getAsyncParam() for the function.

Thanks @rodrigc , trying it in 0ad85ce

@lopuhin
Copy link
Contributor Author

lopuhin commented Feb 27, 2018

Thanks, looks like it fixed the build!

@lopuhin
Copy link
Contributor Author

lopuhin commented Mar 5, 2018

All scrapy tests pass under python 3.7 with this branch. Travis build passed at 30a298a, the last build failed due to an unrelated job erroring out. OS X build was stuck at "Waiting for status to be reported" both times. Is there anything that needs to be fixed?

Copy link
Contributor

@rodrigc rodrigc left a comment

Choose a reason for hiding this comment

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

Without your patch,
if I run the following command in the top level directory of the trunk branch in Twisted:

python -m tox -e pycodestyle

I get a few warnings like:

src/twisted/mail/imap4.py:1105:45: W606 'async' and 'await' are reserved keywords starting with Python 3.7

so your patch definitely fixes the problem.
This is very helpful, since this is a syntax error on Python 3.7.

@@ -151,8 +153,9 @@ def _ebDisplayDeferred(self, failure, k, obj):
return failure


def write(self, data, async=False):
self.handler.addOutput(data, async)
def write(self, data, _async=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

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

instead of _async, can this be renamed to asAsync=True|False ? ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

+1, I like asAsync better than _async. I've seen async_ used in other libraries and it matches the PEP-8, but this name does not pass Twisted style check.

def sendUntaggedResponse(self, message, async=False):
if not async or (self.blocked is None):
def sendUntaggedResponse(self, message, _async=None, **kwargs):
_async = get_async_param(_async, **kwargs)
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't this trigger a deprecation warning?

I expect that in the future code should be updated to just use _async...

but since this is public API I am -1 for using _async as an argument name

and since this is used as a boolean flag, I am +1 for naming it like isAsync or some other name which implies that this is a boolean

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

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

Thanks @lopuhin for working on this and @rodrigc for the review :)

I am -1 on this due to the introduction if _async as a public API and it looks like @lopuhin agreed on doing the full transition and issue a deprecation warning.

@adiroiban
Copy link
Member

The patch looks like fixing all the W606 'async' and 'await' are reserved keywords starting with Python 3.7 issue. I was running it as

$ python admin/pycodestyle-twisted.py --select=W606 src/twisted/

or with tox

$ tox -e pycodestyle '--select=W606 src/twisted/'

As discussed with @adiroiban, this looks like a better choice
because the API is public and it's a binary option
@lopuhin
Copy link
Contributor Author

lopuhin commented Mar 23, 2018

Thanks for review @adiroiban , I changed parameter name to isAsync in ed675f2 and added a deprecation warning in 1634587. Is it fine that the warning does not specify a twisted version when it's deprecated? If it's better to specify it, which version shall it use?

@adiroiban
Copy link
Member

If it's better to specify it, which version shall it use?

I don't know what version to put in deprecations. @exarkun / @hawkowl / @glyph . Any suggestion?

I think that you cat put a placeholder like NEXT, and it will be automatically be updated... but I am not sure how this works and I don't see the documentation for it.

For deprecation, please use these helpers http://twistedmatrix.com/documents/current/api/twisted.python.deprecate.html

and the dev docs at http://twistedmatrix.com/documents/current/core/development/policy/compatibility-policy.html#how-to-deprecate-apis

Please add docstrings to every test :)

@@ -829,6 +830,34 @@ def _bytesRepr(bytestring):



def get_async_param(isAsync=None, **kwargs):
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 that this should be private...as in, it should only be used inside Twisted core and not used by other projects... so this should be def _get_async_param

@exarkun
Copy link
Member

exarkun commented Mar 23, 2018

I intended for the release management tooling to deal with the "NEXT" idea: https://twistedmatrix.com/trac/ticket/3266

That effort seems pretty well stalled. So I suppose it must be a manual release manager task, hopefully not undocumented but who knows. :/

self.assertRaises(TypeError, get_async_param, False, {'async': False})


def test_get_async_param_deprecation(self):
Copy link
Member

Choose a reason for hiding this comment

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

The test should be for the public API itself, and not for this (what should be) private code.

@@ -0,0 +1,3 @@
Syntax error under Python 3.7 fixed for twisted.conch.manhole and
twisted.main.imap4. isAsync keyword argument is used by default instead of
async, async keywoard argument is deprecated.
Copy link
Member

Choose a reason for hiding this comment

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

The deprecation info should be put into a separate file named src/twisted/newsfragments/9384.removal

In this way, the depreciation part of the release notes will contain the info about async keyword.
Otherwise, the bugfix part will contain both bugfix and deprecation.

Copy link
Contributor

@rodrigc rodrigc left a comment

Choose a reason for hiding this comment

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

This line is not being hit during the tests:

https://codecov.io/gh/twisted/twisted/compare/6a1d600241c273b693186f2a166b8e9c5717634e...93864a6674733b48e3264c1fe993858da0cd5c5f/diff#D6-856

Can you fix the code or fix your test so that this line is hit during the tests?

@rodrigc
Copy link
Contributor

rodrigc commented Apr 4, 2018

@lopuhin Can you fix the test?

@lopuhin
Copy link
Contributor Author

lopuhin commented Apr 4, 2018

@rodrigc sure, sorry that I stopped working on it - I plan to resume on Friday, but if someone wants to finish it sooner I'm totally fine with that too :)

@hroncok
Copy link

hroncok commented Jun 5, 2018

@lopuhin How can I help?

@glyph
Copy link
Member

glyph commented Jul 4, 2018

Replying to @exarkun from march:

That effort seems pretty well stalled. So I suppose it must be a manual release manager task, hopefully not undocumented but who knows. :/

https://github.com/twisted/incremental#updating

To do this within Twisted, simply write "Twisted NEXT".

@hawkowl
Copy link
Member

hawkowl commented Jul 16, 2018

Running tests on full builders. If it makes the tests run on 3.7 for imap/manhole, I'm happy.

@hawkowl hawkowl merged commit ee53504 into twisted:trunk Jul 16, 2018
@lopuhin
Copy link
Contributor Author

lopuhin commented Jul 20, 2018

Thanks a lot @hawkowl for finishing and merging the fix, sorry for letting it stall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants