-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
eb023b5
to
decb928
Compare
Codecov Report
@@ 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.
decb928
to
e669c72
Compare
One build failed due to |
Try using |
Thanks @rodrigc for advice.
0ad85ce
to
30a298a
Compare
Thanks, looks like it fixed the build! |
There was a problem hiding this 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.
src/twisted/conch/manhole.py
Outdated
@@ -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): |
There was a problem hiding this comment.
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
? ...
There was a problem hiding this comment.
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.
src/twisted/mail/imap4.py
Outdated
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks like fixing all the
|
As discussed with @adiroiban, this looks like a better choice because the API is public and it's a binary option
Recommend using isAsync instead
Thanks for review @adiroiban , I changed parameter name to |
I don't know what version to put in deprecations. @exarkun / @hawkowl / @glyph . Any suggestion? I think that you cat put a placeholder like 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 :) |
src/twisted/python/compat.py
Outdated
@@ -829,6 +830,34 @@ def _bytesRepr(bytestring): | |||
|
|||
|
|||
|
|||
def get_async_param(isAsync=None, **kwargs): |
There was a problem hiding this comment.
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
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. :/ |
src/twisted/test/test_compat.py
Outdated
self.assertRaises(TypeError, get_async_param, False, {'async': False}) | ||
|
||
|
||
def test_get_async_param_deprecation(self): |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
Can you fix the code or fix your test so that this line is hit during the tests?
@lopuhin Can you fix the test? |
@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 :) |
@lopuhin How can I help? |
Replying to @exarkun from march:
https://github.com/twisted/incremental#updating To do this within Twisted, simply write "Twisted NEXT". |
Running tests on full builders. If it makes the tests run on 3.7 for imap/manhole, I'm happy. |
Thanks a lot @hawkowl for finishing and merging the fix, sorry for letting it stall! |
Syntax error under Python 3.7 fixed for
twisted.conch.manhole
andtwisted.main.imap4
.async_
keyword argument is used by default instead ofasync
, butasync
is also supported for backwards compatibility.Twisted issue: https://twistedmatrix.com/trac/ticket/9384