Skip to content

Adding new attributes to .Net classes is unstable #292

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

Closed
oyse opened this issue Nov 24, 2016 · 1 comment
Closed

Adding new attributes to .Net classes is unstable #292

oyse opened this issue Nov 24, 2016 · 1 comment

Comments

@oyse
Copy link

oyse commented Nov 24, 2016

I have a problem with adding attributes to .Net classes being unstable. E.g.

from System import TimeSpan

TimeSpan.my_method = lambda self: self.TotalMinutes
ts = TimeSpan.FromHours(1)
ts.my_method()

This code will sometimes work and other times fail with the exception 'TimeSpan' object has no attribute 'my_method'.

The failure rate is variable and for some scripts/program it will work all the time while for others it will not work at all. It seems to fail a lot more often on Python 3.5 than on Python 3.4.

If I look at either dir(ts) or ts.__class__.__dict__ the method is there even when the call to my_method fails.

I have tried to look into the PythonNet code for clues, but as far as I can see the new attribute is registered by MetaType. tp_setattro without error, but the method is still not found.

@filmor
Copy link
Member

filmor commented Nov 25, 2016

Closed by #293

@filmor filmor closed this as completed Nov 25, 2016
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

2 participants