Skip to content

Commit

Permalink
Added support for Python 3 async functions and methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Feneric committed Nov 29, 2021
1 parent df99736 commit a739b12
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 0 deletions.
1 change: 1 addition & 0 deletions doxypypy/doxypypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ def visit_FunctionDef(self, node, **kwargs):
self.generic_visit(node, containingNodes=containingNodes)
# Remove the item we pushed onto the containing nodes hierarchy.
containingNodes.pop()
visit_AsyncFunctionDef = visit_FunctionDef

def visit_ClassDef(self, node, **kwargs):
"""
Expand Down
48 changes: 48 additions & 0 deletions doxypypy/test/sample_async.out.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
## @brief An asynchronous function and an asynchronous method.
#
#Here we're testing out some straightforward Python 3 async
#examples.
#
# @namespace sample_async



## @brief A sample non-asynchronous function.
#
# @namespace sample_async.non_asynchronous_function

def non_asynchronous_function():
return "Not async."

## @brief A sample asynchronous function.
#
# @namespace sample_async.asynchronous_function

async def asynchronous_function():
return "Async"


## @brief A sample class with an async method.
#
# Nothing special, just a basic Python 3 class that has an
# async method in it.
#
# @namespace sample_async.ClassWithAsyncMethod

class ClassWithAsyncMethod():

## @brief This is a regular, non-async method.
#
# @namespace sample_async.ClassWithAsyncMethod.non_asynchronous_method

def non_asynchronous_method(self):
return "Not async."

## @brief This is an asynchronous method.
#
# @namespace sample_async.ClassWithAsyncMethod.asynchronous_method

async def asynchronous_method(self):
return "Async"

42 changes: 42 additions & 0 deletions doxypypy/test/sample_async.outbare.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
##
#An asynchronous function and an asynchronous method.
#
#Here we're testing out some straightforward Python 3 async
#examples.
#


##
# A sample non-asynchronous function.
#
def non_asynchronous_function():
return "Not async."

##
# A sample asynchronous function.
#
async def asynchronous_function():
return "Async"


##
# A sample class with an async method.
#
# Nothing special, just a basic Python 3 class that has an
# async method in it.
#
class ClassWithAsyncMethod():

##
# This is a regular, non-async method.
#
def non_asynchronous_method(self):
return "Not async."

##
# This is an asynchronous method.
#
async def asynchronous_method(self):
return "Async"

48 changes: 48 additions & 0 deletions doxypypy/test/sample_async.outnc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
## @brief An asynchronous function and an asynchronous method.
#
#Here we're testing out some straightforward Python 3 async
#examples.
#
# @namespace sample_async



## @brief A sample non-asynchronous function.
#
# @namespace sample_async.non_asynchronous_function

def non_asynchronous_function():
return "Not async."

## @brief A sample asynchronous function.
#
# @namespace sample_async.asynchronous_function

async def asynchronous_function():
return "Async"


## @brief A sample class with an async method.
#
# Nothing special, just a basic Python 3 class that has an
# async method in it.
#
# @namespace sample_async.ClassWithAsyncMethod

class ClassWithAsyncMethod():

## @brief This is a regular, non-async method.
#
# @namespace sample_async.ClassWithAsyncMethod.non_asynchronous_method

def non_asynchronous_method(self):
return "Not async."

## @brief This is an asynchronous method.
#
# @namespace sample_async.ClassWithAsyncMethod.asynchronous_method

async def asynchronous_method(self):
return "Async"

42 changes: 42 additions & 0 deletions doxypypy/test/sample_async.outnn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
## @brief An asynchronous function and an asynchronous method.
#
#Here we're testing out some straightforward Python 3 async
#examples.
#



## @brief A sample non-asynchronous function.
#

def non_asynchronous_function():
return "Not async."

## @brief A sample asynchronous function.
#

async def asynchronous_function():
return "Async"


## @brief A sample class with an async method.
#
# Nothing special, just a basic Python 3 class that has an
# async method in it.
#

class ClassWithAsyncMethod():

## @brief This is a regular, non-async method.
#

def non_asynchronous_method(self):
return "Not async."

## @brief This is an asynchronous method.
#

async def asynchronous_method(self):
return "Async"

42 changes: 42 additions & 0 deletions doxypypy/test/sample_async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
"""
An asynchronous function and an asynchronous method.
Here we're testing out some straightforward Python 3 async
examples.
"""


def non_asynchronous_function():
"""
A sample non-asynchronous function.
"""
return "Not async."

async def asynchronous_function():
"""
A sample asynchronous function.
"""
return "Async"


class ClassWithAsyncMethod():
"""
A sample class with an async method.
Nothing special, just a basic Python 3 class that has an
async method in it.
"""

def non_asynchronous_method(self):
"""
This is a regular, non-async method.
"""
return "Not async."

async def asynchronous_method(self):
"""
This is an asynchronous method.
"""
return "Async"

8 changes: 8 additions & 0 deletions doxypypy/test/test_doxypypy.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,14 @@ def test_indentProcessing(self):
sampleName = 'doxypypy/test/sample_rstexample.py'
self.compareAgainstGoldStandard(sampleName, equalIndent=True)

@mark.skipif(version_info < (3, 0), reason="not supported in Python 2")
def test_asyncProcessing(self):
"""
Test the examples with async functions and methods.
"""
sampleName = 'doxypypy/test/sample_async.py'
self.compareAgainstGoldStandard(sampleName)


if __name__ == '__main__':
# When executed from the command line, run all the tests via unittest.
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
'chardet'
],
test_suite='doxypypy.test.test_doxypypy',
extras_require={
'testing': ['pytest', 'tox'],
},
entry_points={
'console_scripts': [
'doxypypy = doxypypy.doxypypy:main'
Expand Down

0 comments on commit a739b12

Please sign in to comment.