-
Notifications
You must be signed in to change notification settings - Fork 747
Exception when deriving from a .NET class with abstract methods in Python #2571
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
Comments
After some further testing, it looks like it is specifically the method being |
Looks like this is, actually, a duplicate of #2192, though having For now I've forked it with a tweak to allow overriding protected methods. The downside is that all |
Annoyingly, you cannot override protected methods in Python.NET. And this is a big problem for AbstractPdfDocumentEventHandler, as you need to override an `abstract protected` method. Relevant issues: - pythonnet/pythonnet#2213 - pythonnet/pythonnet#2571 I've tried making a Python.NET fork, which allows you to override: - https://github.com/Eswcvlad/pythonnet/tree/protected-override But since the issue has been hanging for a while, I doubt it will be fixed soon. And making a dependency on a fork is not great... Changing this on iText side is not good as well, as it makes the C# API worse... For now, I've patched all AbstractPdfDocumentEventHandler OnAcceptedEvent methods in iText to be public, but this is a very bad solution, as: - You would need to track any new subclasses on updates and patch them as well. - You would need to update these patches for every release. - This only handles one method, while this is a global problem. - If you add another library, which also derives from AbstractPdfDocumentEventHandler, then it will not work, if OnAcceptedEvent remained "protected" there. But it is better than nothing...
Environment
Details
I have an abstract .NET class, which has abstract methods to override within a
netstandard2.0
library. When I try to derive from such a class in Python, it throws aTypeError
during class object creation.Below is a basic example.
.NET library code:
Python code:
Python script output:
The text was updated successfully, but these errors were encountered: