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
Create public aliases for arguments #6
Comments
You can use |
Not if I understand it correctly As for example
This would say that they don't match. |
So? A private class does not prevent its objects from being passed into functions. Using a private class as argument type hints seems totally reasonable to me, and the warning that you get seems a false positive. The convention is lxml is that "private" (starting with an underscore) classes are not meant to be instantiated by users. That doesn't prevent them from being used in other ways, e.g. for typing. |
I know I can use the private classes for typing, but I would say I would be breaking some kinda python rule if my module uses private classes from another module (even if it's only for typing) Also if I do use them, pylance ( and other static tools ) will complain that you are using private classes |
Then I would argue that those tools need to be fixed. Apparently, it's not enough to warn about imported names that simply start with an underscore, it's also relevant what they are used for. If they are not used at all, that's an "unused import" case. If they are getting called or instantiated or otherwise actively used in code, that's a violation of an API contract. If they are used for lxml might be excessive here with its relatively high number of internal classes, but I'm sure it's not the only package where this problem appears. Adding a non-private alias for the |
Closing, since it's a third-party issue. |
The problem I'm trying to solve is having a method that takes an element or elementtree as argument, and forwards that to a XPath object.
If I do this with fx pylance, I would get the complaint that elem is Unknown. If I try to fix this by adding the type, I would have to write
Which of course triggers that the types are private.
For easy fix I would suggest some simple typing aliases
TElement = _Element or something like that (Don't really care about the syntax - more about that the types would be public)
The text was updated successfully, but these errors were encountered: