You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Check for Match instance in Union[Match, str] #2282
It's not clear for me, how should I use Pattern and Match type aliases to pick apart Union[Match, str].
It looks like Match type alias supports __subclasscheck__, but mypy used with
from typing import Match, Union
def process_consumed_issubclass(consumed: Union[Match, str]) -> str:
if issubclass(type(consumed), Match):
return consumed.group('res')
return consumed
returns
test_mypy_match.py: note: In function "process_consumed_issubclass":
test_mypy_match.py:7: error: Some element of union has no attribute "group"
test_mypy_match.py:9: error: Incompatible return value type (got "Union[Match[Any], str]", expected "str")
Match.impl_type have type(stdlib_re.match('', '')), but isinstance check still doesn't work
test_mypy_match.py: note: In function "process_consumed_isinstance":
test_mypy_match.py:13: error: Match[AnyStr] has no attribute "impl_type"
test_mypy_match.py:14: error: Some element of union has no attribute "group"
test_mypy_match.py:16: error: Incompatible return value type (got "Union[Match[Any], str]", expected "str")
Hm, mypy doesn't understand issubclass(type(x), C) at all, and in general that should just be written using isinstance() (which works in mypy). But I understand that typing.py doesn't support this, even though it should. Can you file a bug about that in https://github.com/python/typing/issues ?
Activity
gvanrossum commentedon Oct 19, 2016
mkurnikov commentedon Oct 19, 2016
Reverse check works fine, thanks. The issue was meant to be a bug report, feel free to close it, if it's irrelevant.
gvanrossum commentedon Oct 19, 2016
Hm, mypy doesn't understand
issubclass(type(x), C)at all, and in general that should just be written usingisinstance()(which works in mypy). But I understand that typing.py doesn't support this, even though it should. Can you file a bug about that in https://github.com/python/typing/issues ?mkurnikov commentedon Oct 19, 2016
It looks like it's fixed in
python/typingalready with python/typing#283:https://github.com/python/typing/blame/master/src/typing.py#L312
It just hasn't been released yet.
gvanrossum commentedon Oct 19, 2016