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

Warn if a Trait default method raises AttributeError #1762

Merged
merged 3 commits into from
Jan 11, 2024

Conversation

mdickinson
Copy link
Member

Closes #1747

This PR issues a UserWarning when a *_default trait default method raises an AttributeError, to help detect an otherwise easy-to-miss failure mode.

Checklist

  • Tests
  • Update API reference (docs/source/traits_api_reference)
  • Update User manual (docs/source/traits_user_manual)
  • Update type annotation hints in stub files

Copy link
Contributor

@corranwebster corranwebster left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Am trusting somewhat on the reference clean-up in the helper function being correct.

One suggestion is that the test seems to only test one of the two code paths for the default generation (although it is likely the most important one to catch).

@mdickinson
Copy link
Member Author

the test seems to only test one of the two code paths for the default generation

Good point; fixed in 4819297

I've also suppressed an instance of the new warning from an existing test in 45a2e1d.

@mdickinson mdickinson merged commit 9778f4d into main Jan 11, 2024
32 checks passed
@mdickinson mdickinson deleted the fix/warn-on-attribute-error-from-default branch January 11, 2024 09:16
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

Successfully merging this pull request may close these issues.

AttributeErrors are silently caught by trait_get()
2 participants