Skip to content
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

Can't define a typing.Union containing a typing.re.Pattern #69577

Closed
MartCongostTapias mannequin opened this issue Oct 13, 2015 · 3 comments
Closed

Can't define a typing.Union containing a typing.re.Pattern #69577

MartCongostTapias mannequin opened this issue Oct 13, 2015 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@MartCongostTapias
Copy link
Mannequin

MartCongostTapias mannequin commented Oct 13, 2015

BPO 25390
Nosy @gvanrossum, @zhangyangyu

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/gvanrossum'
closed_at = <Date 2015-10-19.21:57:04.177>
created_at = <Date 2015-10-13.09:27:47.517>
labels = ['type-bug', 'library']
title = "Can't define a typing.Union containing a typing.re.Pattern"
updated_at = <Date 2015-10-19.21:57:04.176>
user = 'https://bugs.python.org/MartCongostTapias'

bugs.python.org fields:

activity = <Date 2015-10-19.21:57:04.176>
actor = 'gvanrossum'
assignee = 'gvanrossum'
closed = True
closed_date = <Date 2015-10-19.21:57:04.177>
closer = 'gvanrossum'
components = ['Library (Lib)']
creation = <Date 2015-10-13.09:27:47.517>
creator = 'Mart\xc3\xad Congost Tapias'
dependencies = []
files = []
hgrepos = []
issue_num = 25390
keywords = []
message_count = 3.0
messages = ['252923', '252937', '253198']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'python-dev', 'xiang.zhang', 'Mart\xc3\xad Congost Tapias']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25390'
versions = ['Python 3.5']

@MartCongostTapias
Copy link
Mannequin Author

MartCongostTapias mannequin commented Oct 13, 2015

Defining a union of typing.re.Pattern and anything that isn't AnyStr raises a TypeError exception.

Example:

from typing import Union, re

def foo(pattern: Union[str, re.Pattern]) -> None:
    pass

Exception traceback:

Traceback (most recent call last):
  File "/tmp/testtyping.py", line 7, in <module>
    def foo(pattern: Union[str, re.Pattern]) -> None:
  File "/usr/local/lib/python3.5/typing.py", line 534, in __getitem__
    dict(self.__dict__), parameters, _root=True)
  File "/usr/local/lib/python3.5/typing.py", line 491, in __new__
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
  File "/usr/local/lib/python3.5/typing.py", line 491, in <genexpr>
    for t2 in all_params - {t1} if not isinstance(t2, TypeVar)):
TypeError: issubclass() arg 1 must be a class

@MartCongostTapias MartCongostTapias mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error stdlib Python modules in the Lib dir and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Oct 13, 2015
@gvanrossum
Copy link
Member

Confirmed. The failure is because Pattern is _TypeAlias, which is not a type. But it should be allowed. I'll think of something. (Does mypy accept this?)

@gvanrossum gvanrossum self-assigned this Oct 13, 2015
@python-dev
Copy link
Mannequin

python-dev mannequin commented Oct 19, 2015

New changeset 955d3faf727a by Guido van Rossum in branch '3.5':
Issue bpo-25390: typing: Don't crash on Union[str, Pattern].
https://hg.python.org/cpython/rev/955d3faf727a

New changeset 04314479af0b by Guido van Rossum in branch 'default':
Issue bpo-25390: typing: Don't crash on Union[str, Pattern]. (Merge 3.5->3.6)
https://hg.python.org/cpython/rev/04314479af0b

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant