ElementTree.iselement() returns true for the Element type
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
According to documentation, ElementTree.iselement() check if the argument is an element object.
But it returns true also for the Element type which has all attributes of an Element instance. The way how the Element class is defined in Python suggests that this may be intentional, but the intention was lost in the documentation.
There is also an example of dataclasses.is_dataclass() which returns true both for a dataclass type and for a dataclass instance.
So, there are two ways:
- Fix the documentation to match the current behavior. All uses of
iselement()(see #135640) should also check if the argument is a type is they need an element object. - Fix the implementation to check if the argument is a type. This may break the user code that uses it to check for the Element type (I don't know if it exists) but may fix bugs in the user code which expects that
iselement()works as documented.
cc @scoder
Linked PRs
- gh-136482
- gh-136484
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the ElementTree.iselement() documentation and implementation, then inspect linked PRs gh-136482 and gh-136484 and the uses referenced in #135640. Done means resolving whether the documented behavior or the implementation should change, and updating the relevant behavior or documentation consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100