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 python 3.12 compatability issue #20

Merged
merged 3 commits into from
Nov 3, 2024
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
12 changes: 10 additions & 2 deletions src/pymdgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ def getargspec(func):
decorated functions
"""
if hasattr(func, "__wrapped__"):
return inspect.getfullargspec(func.__wrapped__)
return inspect.getfullargspec(func)
func = func.__wrapped__

sig = inspect.signature(func)
return [
list(sig.parameters),
None,
None,
[param.default for param in sig.parameters.values() if param.default != inspect.Parameter.empty],
]



def doc_func(name, func, section_level=4):
Expand Down
45 changes: 45 additions & 0 deletions src/pymdgen/test_getargspec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import inspect
from functools import wraps
from pymdgen import getargspec # Import your __init__.py module


def test_getargspec_simple_function():
def my_function(a, b, c=10):
pass
expected_result = [
['a', 'b', 'c'],
None,
None,
[10,],
]
assert getargspec(my_function) == expected_result

def test_getargspec_args_kwargs():
def my_function(a, b, *args, **kwargs):
pass
expected_result = [
['a', 'b', 'args', 'kwargs'],
None,
None,
[],
]
assert getargspec(my_function) == expected_result

def test_getargspec_decorated_function():
def my_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
return func(*args, **kwargs)
return wrapper

@my_decorator
def my_function(a, b, c=20):
pass

expected_result = [
['a', 'b', 'c'],
None,
None,
[20,],
]
assert getargspec(my_function) == expected_result
Loading