Skip to content

Reveal metaclass base-class to type-checker #1489

Answered by erictraut
scanny asked this question in Q&A
Discussion options

You must be logged in to vote

Thanks, I'm able to repro the issue now. The problem is that the lxml stubs indicate that lxml.etree._Element subclasses from Sized, which uses an ABCMeta metaclass. At runtime, lxml.etree._Element does not derive from Sized, so this appears to be a bug in the lxml type stubs, which are not accurately reflecting the implementation. You can work around the issue in your code by adding a # type: ignore or # pyright: ignore.

It occurs to me that pyright's error message in this case could be improved. I've updated the code accordingly, and future releases of pyright will now report the specific metaclasses that are causing the conflict.

Replies: 2 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@scanny
Comment options

@erictraut
Comment options

@scanny
Comment options

@erictraut
Comment options

Answer selected by scanny
@scanny
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants