Skip to content

Conversation

@aditya-singh597
Copy link
Contributor

@aditya-singh597 aditya-singh597 commented Jan 27, 2026

PR Summary

As mentioned in #30979, set is not tested directly even though it is used in many places.

These tests lock in the current behaviour:

-passing an invalid property name raises an AttributeError, and
-providing both a property and its alias (for example lw and linewidth) raises a TypeError.

The behaviour already exists at runtime; these tests just make sure it doesn’t change by accident.

PR checklist

  • [N/A] "closes #0000" is in the body of the PR description
  • new and changed code is tested
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New Features and API Changes are noted with a directive and release note
  • [N/A] Documentation complies with general and docstring guidelines

@aditya-singh597
Copy link
Contributor Author

Hi @story645 , Can you please review.

@story645
Copy link
Member

Is their context for this change? Like a discussion in a PR or something? I'm unclear what problem it's fixing given there wasn't a coverage failure.

@aditya-singh597
Copy link
Contributor Author

There wasn’t any recent coverage failure behind this change. The goal is just to make the current behavior explicit, setp already raises an AttributeError when an invalid property name is passed, but there wasn’t a test that directly checked this.

@rcomer
Copy link
Member

rcomer commented Jan 28, 2026

setp itself does not do any checking on the parameter name, but just passes it straight to the artists' set method. So I think if we're going to add this, it should be a test on set not setp.

If we completely remove the specific error within _update_props, then it will just try to call

In [4]: line.set_not_a_property(1)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[4], line 1
----> 1 line.set_not_a_property(1)

AttributeError: 'Line2D' object has no attribute 'set_not_a_property'

So we still get an AttributeError and the test still passes. But the error message is not what we want, so the test should also check the message.

As discussed in #30979, the set method is generally lacking in tests. Since that PR is unlikely to progress quickly, you are welcome to pull the new test out of there and add some for exceptions, including the one about not accepting duplicate aliases.

@aditya-singh597
Copy link
Contributor Author

Thank you for the clarification. I’ll rework the tests accordingly and push an update.

@rcomer
Copy link
Member

rcomer commented Jan 29, 2026

Thanks @aditya-singh597. I'm going to mark this as "draft" for now. Please mark it as "ready for review" when you are ready. In the meantime, if you need help, feel free to ask questions here. Or you may prefer to ask them in our incubator chat.

@rcomer rcomer marked this pull request as draft January 29, 2026 13:41
@aditya-singh597
Copy link
Contributor Author

Sure. I'll mark it ready for review when I'm done.

@aditya-singh597 aditya-singh597 changed the title Add test for invalid property names passed to setp Add tests for invalid properties and duplicate aliases in Artist.set Jan 29, 2026
@aditya-singh597 aditya-singh597 marked this pull request as ready for review January 29, 2026 22:31
@rcomer rcomer added this to the v3.11.0 milestone Feb 2, 2026
@rcomer rcomer merged commit 01fdf1b into matplotlib:main Feb 2, 2026
43 checks passed
@rcomer
Copy link
Member

rcomer commented Feb 2, 2026

Thanks @aditya-singh597 and congratulations on your first Matplotlib PR 🎉 Hopefully we will hear from you again.

@aditya-singh597
Copy link
Contributor Author

@rcomer
Thank you for the guidance, it was very helpful.

@aditya-singh597 aditya-singh597 deleted the test-setp-invalid-property branch February 2, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants