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

super().__init__() throws TypeError: No method matches given arguments for Object..ctor: () #2265

Open
welbouri opened this issue Oct 12, 2023 · 4 comments

Comments

@welbouri
Copy link

Environment

  • Pythonnet version: 3.0.3
  • Python version: 3.10.10
  • Operating System: Windows 10
  • .NET Runtime: net6.0

Details

  • Create a python class that inherits from a C# class
  • Instantiate a python object from that python class

Please find attached a minimal project that shows the sporadic exception.

pythonnet.issue.zip

  • PythonnetIssue : C# minimal project
  • superInit : python project to rerpoduce the issue

Exception

TypeError: Invoked a non-static method with an invalid instance

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\workspace\pythonnet.issue\superInit\main.py", line 15, in <module>
    a = PythonClass('name')
  File "D:\workspace\pythonnet.issue\superInit\main.py", line 9, in __init__
    super().__init__()
TypeError: No method matches given arguments for ParentClass..ctor: ()
@lostmsu
Copy link
Member

lostmsu commented Oct 12, 2023

Can you inline the ParentClass here?

@welbouri
Copy link
Author

namespace PythonnetIssue
{
    public class ParentClass
    {
        public ParentClass()
        {

        }
    }
}

@welbouri
Copy link
Author

Hint : From what I have found in some other cases, I am doubting that the sporadic exception thrown by super().__init__() occurs when we set __namespace__

@goncalogiga
Copy link

goncalogiga commented Mar 14, 2024

Hello,

I am also facing this issue when inheriting a python class from AstVisitor:

TypeError: Invoked a non-static method with an invalid instance

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/usr/lib/python3.10/multiprocessing/pool.py", line 51, in starmapstar
    return list(itertools.starmap(args[0], args[1]))
  File "/home/user/pythonnet_project/feature_extraction/feature_extraction.py", line 49, in compute_powershell_features
    **get_structural_features(ast),
  File "/home/user/pythonnet_project/feature_extraction/structural.py", line 147, in get_structural_features
    return ast.GetFeatures(AST_NODES_TYPES) if ast else {}
  File "/home/user/pythonnet_project/feature_extraction_utils/pspython.py", line 180, in GetFeatures
    visitor = PyAstVisitor(ast_node_types)
  File "/home/user/pythonnet_project/feature_extraction_utils/pspython.py", line 77, in __init__
    super().__init__(*args, **kwargs)
TypeError: No method matches given arguments for AstVisitor..ctor: ()

Like welbouri said, the exception is raised randomly after around 30000+ instantiations of the python class. In our case, skipping __namespace__ is not possible, since AstVisitor is an abstract class. Any updates on this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants