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

Concatenate is not covered to be a return type in test_typing #90553

Closed
sobolevn opened this issue Jan 16, 2022 · 5 comments
Closed

Concatenate is not covered to be a return type in test_typing #90553

sobolevn opened this issue Jan 16, 2022 · 5 comments
Labels
3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

BPO 46395
Nosy @gvanrossum, @sobolevn, @Fidget-Spinner
PRs
  • bpo-46395: cover Concatenate as return type in test_typing #30618
  • 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 = None
    closed_at = <Date 2022-01-16.10:01:17.698>
    created_at = <Date 2022-01-16.08:27:37.365>
    labels = ['invalid', 'type-bug', 'tests', '3.11']
    title = '`Concatenate` is not covered to be a return type in `test_typing`'
    updated_at = <Date 2022-01-16.10:01:17.697>
    user = 'https://github.com/sobolevn'

    bugs.python.org fields:

    activity = <Date 2022-01-16.10:01:17.697>
    actor = 'sobolevn'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-16.10:01:17.698>
    closer = 'sobolevn'
    components = ['Tests']
    creation = <Date 2022-01-16.08:27:37.365>
    creator = 'sobolevn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46395
    keywords = ['patch']
    message_count = 5.0
    messages = ['410681', '410685', '410686', '410689', '410691']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'sobolevn', 'kj']
    pr_nums = ['30618']
    priority = 'normal'
    resolution = 'not a bug'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue46395'
    versions = ['Python 3.11']

    @sobolevn
    Copy link
    Member Author

    Right now all Concatenate tests do not cover Callable[..., Concatenate] case.

    Link:

    P = ParamSpec('P')
    T = TypeVar('T')
    C1 = Callable[Concatenate[int, P], int]
    self.assertEqual(C1.__args__, (Concatenate[int, P], int))
    self.assertEqual(C1.__parameters__, (P,))
    C2 = Callable[Concatenate[int, T, P], T]
    self.assertEqual(C2.__args__, (Concatenate[int, T, P], T))
    self.assertEqual(C2.__parameters__, (T, P))
    # Test collections.abc.Callable too.
    C3 = collections.abc.Callable[Concatenate[int, P], int]
    self.assertEqual(C3.__args__, (Concatenate[int, P], int))
    self.assertEqual(C3.__parameters__, (P,))
    C4 = collections.abc.Callable[Concatenate[int, T, P], T]
    self.assertEqual(C4.__args__, (Concatenate[int, T, P], T))
    self.assertEqual(C4.__parameters__, (T, P))

    I think, that this should be improved. It is an important case.
    PR is on its way.

    @sobolevn sobolevn added 3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error labels Jan 16, 2022
    @Fidget-Spinner
    Copy link
    Member

    Sorry I'm confused: Callable[..., Concatenate] is invalid usage. So I don't think we need to test it.

    https://docs.python.org/3/library/typing.html#typing.Concatenate. "Concatenate is currently only valid when used as the first argument to a Callable."

    @sobolevn
    Copy link
    Member Author

    Sorry I'm confused: Callable[..., Concatenate] is invalid usage. So I don't think we need to test it.

    Yes, my bad :)

    In this case, do we need to make this a TypeError? Right now you can use Concatenate as the return type.

    @Fidget-Spinner
    Copy link
    Member

    In this case, do we need to make this a TypeError? Right now you can use Concatenate as the return type.

    Last I recall, we stopped checking anything in the param args of Callable since 3.10 because it has too many problems with inter-version typing and typing_extensions usage. E.g. in Python 3.8

    Callable[typing_extensions.Concatenate[...], ...]

    was extremely difficult to implement in typing_extensions since Callable checks were too strict back then (they only allowed list of args). So to avoid such problems in the future, we ceased all param args checking.

    For the return arg, I'm not too keen on adding more checks for the same reason of allowing future additions. Also the static type checker should warn the user and mypy correctly does that.

    @sobolevn
    Copy link
    Member Author

    Thank you for the explanation, Ken Jin.

    Going to close this issue as invalid.

    @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
    3.11 only security fixes tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants