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
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=Noneclosed_at=<Date2022-01-24.16:10:16.872>created_at=<Date2022-01-22.10:16:13.368>labels= ['type-bug', 'library', '3.11']
title='`_remove_dups_flatten` in `typing.py` contains dead branch'updated_at=<Date2022-01-24.16:10:16.872>user='https://github.com/sobolevn'
Here's how _remove_dups_flatten is defined right now:
def _remove_dups_flatten(parameters):
"""An internal helper for Union creation and substitution: flatten Unions
among parameters, then remove duplicates.
"""
# Flatten out Union[Union[...], ...].
params = []
for p in parameters:
if isinstance(p, (_UnionGenericAlias, types.UnionType)):
params.extend(p.__args__)
elif isinstance(p, tuple) and len(p) > 0 and p[0] is Union:
params.extend(p[1:])
else:
params.append(p)
return tuple(_deduplicate(params))
parameters = tuple(_type_check(p, msg) for p in parameters)
parameters = _remove_dups_flatten(parameters)
But, notice that `_remove_dups_flatten` contains this branch: `elif isinstance(p, tuple) and len(p) > 0 and p[0] is Union:`.
It is never executed, removing it does not change test_typing / test_types results. And it is reasonable: _type_check ensures that parameters can only contain types, not tuples.
Proof:
>>> from typing import Union, get_type_hints
>>> Union[int, (Union, str, bool)]
# TypeError: Union[arg, ...]: each arg must be a type. Got (typing.Union, <class 'str'>, <class 'bool'>).
>>> class Some:
... x: 'Union[int, (Union, str, bool)]'
...
>>> get_type_hints(Some)
# TypeError: Union[arg, ...]: each arg must be a type. Got (typing.Union, <class 'str'>, <class 'bool'>).
Since it is pretty old, I guess the internal API has changed significantly and it is not needed anymore.
typing._remove_dups_flatten
#30780Note: 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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: