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

addressing issue 114: await async rule does not account for decorators #150

Merged
merged 6 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion fixit/rules/await_async_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,43 @@ 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:
@classmethod
async def _method(cls): pass
await Foo._method()
""",
),
Invalid(
"""
class Foo:
@staticmethod
async def _method(self): pass
Foo._method()
""",
expected_replacement="""
class Foo:
@staticmethod
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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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]"
}
]
}
Original file line number Diff line number Diff line change
@@ -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]"
}
]
}