From 1614405d27a0fab207200c106c4c5db8af7d5ffe Mon Sep 17 00:00:00 2001 From: Haroldo Date: Fri, 16 Oct 2020 13:22:03 -0700 Subject: [PATCH 1/6] addressing issue 114: await async rule does not account for decorators --- fixit/rules/await_async_call.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fixit/rules/await_async_call.py b/fixit/rules/await_async_call.py index c325f0b7..9bc705a4 100644 --- a/fixit/rules/await_async_call.py +++ b/fixit/rules/await_async_call.py @@ -289,11 +289,38 @@ async def bar() -> bool: pass while not await bar(): pass """, ), + Invalid( + """ + class Foo: + @classmethod + async def _method(cls): pass + Foo._method() + """, + expected_replacement=""" + class Foo: + async def _method(self): pass + await Foo._method() + """, + ), + Invalid( + """ + class Foo: + @staticmethod + async def _method(self): pass + Foo._method() + """, + expected_replacement=""" + class Foo: + async def _method(self): pass + await Foo._method() + """, + ), ] @staticmethod def _is_awaitable_callable(annotation: str) -> bool: - if not annotation.startswith("typing.Callable"): + if not (annotation.startswith("typing.Callable") + or annotation.startswith("typing.ClassMethod") or annotation.startswith("StaticMethod")): # Exit early if this is not even a `typing.Callable` annotation. return False try: From ee5a813a3ecff489b597292c5ee89796f0a70d15 Mon Sep 17 00:00:00 2001 From: Haroldo Date: Fri, 16 Oct 2020 14:43:54 -0700 Subject: [PATCH 2/6] fixing spacing --- fixit/rules/await_async_call.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fixit/rules/await_async_call.py b/fixit/rules/await_async_call.py index 9bc705a4..5aba5f11 100644 --- a/fixit/rules/await_async_call.py +++ b/fixit/rules/await_async_call.py @@ -319,8 +319,8 @@ async def _method(self): pass @staticmethod def _is_awaitable_callable(annotation: str) -> bool: - if not (annotation.startswith("typing.Callable") - or annotation.startswith("typing.ClassMethod") or annotation.startswith("StaticMethod")): + if not (annotation.startswith("typing.Callable") + or annotation.startswith("typing.ClassMethod") or annotation.startswith("StaticMethod")): # Exit early if this is not even a `typing.Callable` annotation. return False try: From 596c78847feb76c0938c7a87d604972cf04f006b Mon Sep 17 00:00:00 2001 From: Haroldo Date: Fri, 16 Oct 2020 16:03:58 -0700 Subject: [PATCH 3/6] fixing lint --- fixit/rules/await_async_call.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fixit/rules/await_async_call.py b/fixit/rules/await_async_call.py index 5aba5f11..0c98e4fe 100644 --- a/fixit/rules/await_async_call.py +++ b/fixit/rules/await_async_call.py @@ -319,8 +319,11 @@ async def _method(self): pass @staticmethod def _is_awaitable_callable(annotation: str) -> bool: - if not (annotation.startswith("typing.Callable") - or annotation.startswith("typing.ClassMethod") or annotation.startswith("StaticMethod")): + if not ( + annotation.startswith("typing.Callable") + or annotation.startswith("typing.ClassMethod") + or annotation.startswith("StaticMethod") + ): # Exit early if this is not even a `typing.Callable` annotation. return False try: From 04dabc235f32f67f7b5601a74758d8eea8faf018 Mon Sep 17 00:00:00 2001 From: Haroldo Date: Fri, 16 Oct 2020 16:16:22 -0700 Subject: [PATCH 4/6] fixing lint --- fixit/rules/await_async_call.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixit/rules/await_async_call.py b/fixit/rules/await_async_call.py index 0c98e4fe..4e55f1a2 100644 --- a/fixit/rules/await_async_call.py +++ b/fixit/rules/await_async_call.py @@ -321,7 +321,7 @@ async def _method(self): pass def _is_awaitable_callable(annotation: str) -> bool: if not ( annotation.startswith("typing.Callable") - or annotation.startswith("typing.ClassMethod") + or annotation.startswith("typing.ClassMethod") or annotation.startswith("StaticMethod") ): # Exit early if this is not even a `typing.Callable` annotation. From 98dd95aaba74ffd9f778dac40264592afa9afccb Mon Sep 17 00:00:00 2001 From: Haroldo Date: Mon, 19 Oct 2020 15:27:07 -0700 Subject: [PATCH 5/6] fixing invalid correction --- fixit/rules/await_async_call.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fixit/rules/await_async_call.py b/fixit/rules/await_async_call.py index 4e55f1a2..84c521bd 100644 --- a/fixit/rules/await_async_call.py +++ b/fixit/rules/await_async_call.py @@ -298,7 +298,8 @@ async def _method(cls): pass """, expected_replacement=""" class Foo: - async def _method(self): pass + @classmethod + async def _method(cls): pass await Foo._method() """, ), @@ -311,6 +312,7 @@ async def _method(self): pass """, expected_replacement=""" class Foo: + @staticmethod async def _method(self): pass await Foo._method() """, From 50f09e4474880c68ba06c7d15b4c6eb3d9ac30d1 Mon Sep 17 00:00:00 2001 From: Haroldo Date: Fri, 6 Nov 2020 10:15:02 -0800 Subject: [PATCH 6/6] adding generated fixtures --- .../AwaitAsyncCallRule_INVALID_16.json | 95 +++++++++++++++++++ .../AwaitAsyncCallRule_INVALID_17.json | 95 +++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_16.json create mode 100644 fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_17.json diff --git a/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_16.json b/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_16.json new file mode 100644 index 00000000..3672190f --- /dev/null +++ b/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_16.json @@ -0,0 +1,95 @@ +{ + "types": [ + { + "location": { + "start": { + "line": 1, + "column": 6 + }, + "stop": { + "line": 1, + "column": 9 + } + }, + "annotation": "typing.Type[fixit.tests.fixtures.await_async_call.tmp88jl7yhf.Foo]" + }, + { + "location": { + "start": { + "line": 2, + "column": 5 + }, + "stop": { + "line": 2, + "column": 16 + } + }, + "annotation": "typing.Type[classmethod]" + }, + { + "location": { + "start": { + "line": 3, + "column": 14 + }, + "stop": { + "line": 3, + "column": 21 + } + }, + "annotation": "typing.Callable(fixit.tests.fixtures.await_async_call.tmp88jl7yhf.Foo._method)[[], typing.Coroutine[typing.Any, typing.Any, unknown]]" + }, + { + "location": { + "start": { + "line": 3, + "column": 22 + }, + "stop": { + "line": 3, + "column": 25 + } + }, + "annotation": "typing.Type[fixit.tests.fixtures.await_async_call.tmp88jl7yhf.Foo]" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 3 + } + }, + "annotation": "typing.Type[fixit.tests.fixtures.await_async_call.tmp88jl7yhf.Foo]" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 11 + } + }, + "annotation": "typing.Callable(fixit.tests.fixtures.await_async_call.tmp88jl7yhf.Foo._method)[[], typing.Coroutine[typing.Any, typing.Any, unknown]]" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 13 + } + }, + "annotation": "typing.Coroutine[typing.Any, typing.Any, unknown]" + } + ] +} diff --git a/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_17.json b/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_17.json new file mode 100644 index 00000000..75c10af2 --- /dev/null +++ b/fixit/tests/fixtures/await_async_call/AwaitAsyncCallRule_INVALID_17.json @@ -0,0 +1,95 @@ +{ + "types": [ + { + "location": { + "start": { + "line": 1, + "column": 6 + }, + "stop": { + "line": 1, + "column": 9 + } + }, + "annotation": "typing.Type[fixit.tests.fixtures.await_async_call.tmpe9g2w713.Foo]" + }, + { + "location": { + "start": { + "line": 2, + "column": 5 + }, + "stop": { + "line": 2, + "column": 17 + } + }, + "annotation": "typing.Type[staticmethod]" + }, + { + "location": { + "start": { + "line": 3, + "column": 14 + }, + "stop": { + "line": 3, + "column": 21 + } + }, + "annotation": "typing.Callable(fixit.tests.fixtures.await_async_call.tmpe9g2w713.Foo._method)[[Named(self, unknown)], typing.Coroutine[typing.Any, typing.Any, unknown]]" + }, + { + "location": { + "start": { + "line": 3, + "column": 22 + }, + "stop": { + "line": 3, + "column": 26 + } + }, + "annotation": "typing.Any" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 3 + } + }, + "annotation": "typing.Type[fixit.tests.fixtures.await_async_call.tmpe9g2w713.Foo]" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 11 + } + }, + "annotation": "typing.Callable(fixit.tests.fixtures.await_async_call.tmpe9g2w713.Foo._method)[[Named(self, unknown)], typing.Coroutine[typing.Any, typing.Any, unknown]]" + }, + { + "location": { + "start": { + "line": 4, + "column": 0 + }, + "stop": { + "line": 4, + "column": 13 + } + }, + "annotation": "typing.Coroutine[typing.Any, typing.Any, unknown]" + } + ] +}