Skip to content

Fix Py3 bug in getting function name when CV storage raises error #830

Merged
dwhswenson merged 2 commits into
openpathsampling:masterfrom
ajsilveira:master
Jul 25, 2019
Merged

Fix Py3 bug in getting function name when CV storage raises error #830
dwhswenson merged 2 commits into
openpathsampling:masterfrom
ajsilveira:master

Conversation

@ajsilveira

Copy link
Copy Markdown
Contributor

func_name is not an attribute of FunctionCV

@dwhswenson

Copy link
Copy Markdown
Member

Actually, this is a Python 2.7/3.x issue; the issue is with the function that the FunctionCV is wrapping around. See https://docs.python.org/3/whatsnew/3.0.html#operators-and-special-methods. We still support Python 2.7, so this should be set up in a way that works in both 2.7 and 3.x. You probably need something like this (at the top of the file; module-level):

if sys.version_info > (3, ):
    get_callable_name = lambda c: c.__name__
else:
    get_callable_name = lambda c: c.func_name

(then use get_callable_name to get the name).

Also, I assume that you found this because something happened that raised an error message (since this is in an error message). I just wrote up some docs on making CVs that will, I hope, make it a little clearer! See #831.

@ajsilveira

Copy link
Copy Markdown
Contributor Author

Yes. I was not importing the modules. Thanks for that link!.

@dwhswenson

Copy link
Copy Markdown
Member

Please note that we have changed to the OPS license from LGPL (2.1 or later) to MIT. For any pull request to OPS that was started while the license was still LGPL, I need an explicit confirmation that you approve of the license change. Please add a comment with something like "The changes in this pull request are licensed under the MIT license."

@ajsilveira

Copy link
Copy Markdown
Contributor Author

The changes in this pull request are licensed under the MIT license.

@dwhswenson dwhswenson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works! Thanks for the fix.

@dwhswenson dwhswenson merged commit 77508b8 into openpathsampling:master Jul 25, 2019
@dwhswenson dwhswenson added the bugfix PRs fixing bugs label Jul 25, 2019
@dwhswenson dwhswenson changed the title fix bug when getting the name of the function used to define the cv Fix Py3 bug in getting function name when CV storage raises error Jul 25, 2019
This was referenced Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PRs fixing bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants