Skip to content

re functions str/unicode problems #273

Closed
@Dakkaron

Description

@Dakkaron

Currenty all functions in re are typed with AnyStr, so for example re.match is defined as follows:

@overload
def match(pattern: AnyStr, string: AnyStr, flags: int = ...) -> Match[AnyStr]: ...

This is a problem, because since AnyStris defined as

AnyStr = TypeVar('AnyStr', bytes, str)

You cannot use, for example, a str pattern on an unicode string, which does work fine in Python 2.7.

Which way should this be changed to, so that typeshed reflects the reality?

The same problem appears in a lot of places, since it is used as if it was Union[str, unicode].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions