Skip to content

Conversation

martindemello
Copy link
Contributor

xml.sax.saxutils accepts unicode keys and values in its entitles dict

def escape(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ...
def unescape(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ...
def quoteattr(data: AnyStr, entities: Mapping[str, str] = ...) -> AnyStr: ...
def escape(data: AnyStr, entities: Mapping[Union[str, Text], Union[str, Text]] = ...) -> AnyStr: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return type isn't quite right anymore. On my machine, I see (in Python 2):

>>> from xml.sax import saxutils
>>> saxutils.escape('a', {'a': u'd'})
u'd'
>>> saxutils.escape('a', {u'a': 'd'})
u'd'

So the return type doesn't necessary match the type of data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! so i suppose most generally all types should be Union[str, Text]] even though that loses us a bit of information in the cases where AnyStr was correcy

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just used Text; Union[str, Text] is redundant in Python 3, and in Python 2, Text should be used for something that can be either bytes or unicode (https://github.com/python/typeshed/blob/master/CONTRIBUTING.md).

@rchen152 rchen152 merged commit 0c9f0d2 into python:master Jul 24, 2018
@martindemello martindemello deleted the sax-xml-strings branch July 24, 2018 18:19
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants