-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Added several missing annotations to serializer.pyi #15000
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
base: main
Are you sure you want to change the base?
Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
donBarbos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! But it seems like adding types-six here is redundant, since only text_type alias for str is used.
| version = "1.1.*" | ||
| upstream_repository = "https://github.com/html5lib/html5lib-python" | ||
|
|
||
| requires = ["six"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to use types for six, you need to add types-six since the types are distributed separately:
| requires = ["six"] | |
| requires = ["types-six"] |
| from six import text_type | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See below
| from six import text_type |
| def encode(self, string: text_type) -> str: ... | ||
| def encodeStrict(self, string: text_type) -> str: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But since you are only using text_type (adding types-six specifically), this doesn't make sense, since text_type is just an alias for str.
Also, both methods could return bytes if self.encoding is set:
| def encode(self, string: text_type) -> str: ... | |
| def encodeStrict(self, string: text_type) -> str: ... | |
| def encode(self, string: str) -> str | bytes: ... | |
| def encodeStrict(self, string: str) -> str | bytes: ... |
| encoding: Incomplete | ||
| def serialize(self, treewalker, encoding=None) -> Generator[Incomplete]: ... | ||
| def render(self, treewalker, encoding=None): ... | ||
| def serialize(self, treewalker: str, encoding: str) -> str: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Indeed,
encodingcould acceptstr, but it is an optional argument (this is what causes problems with CI passing). treewalkerlooks like someIterableof dictionaries (i'd call it_Token), but since we don't have_TokenTypedDict yet, I suggest usingIterable[dict[str, Incomplete]]serializedoesn't just return a string, it yields it, and since with the encoding set, it can be bytes. I think you can useIteratororGenerator
| def serialize(self, treewalker: str, encoding: str) -> str: ... | |
| def serialize(self, treewalker: Iterable[dict[str, Incomplete]], encoding: str | None = None) -> Iterator[str | bytes]: ... |
| def serialize(self, treewalker, encoding=None) -> Generator[Incomplete]: ... | ||
| def render(self, treewalker, encoding=None): ... | ||
| def serialize(self, treewalker: str, encoding: str) -> str: ... | ||
| def render(self, treewalker: str, encoding: str) -> str: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here (except return type)
But I suggest you use overload here to differentiate between cases where str is returned and cases where bytes is returned
| def render(self, treewalker: str, encoding: str) -> str: ... | |
| @overload | |
| def render(self, treewalker: Iterable[dict[str, Incomplete]], encoding: Literal[""] | None = None) -> bytes: ... | |
| @overload | |
| def render(self, treewalker: Iterable[dict[str, Incomplete]], encoding: str) -> str: ... |
|
@donBarbos Than you very much - i will study all your explanation and follow all tour advices. It will be very useful for me because I am planning to continue contribute to typeshed |
Added several missing annotations to serializer.pyi
Also I have added "six" library to Metadata.toml