Visitar URL original
gh-98852: Add extra type check to avoid a bug with parameterizing gen… by Eclips4 · Pull Request #98862 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221031135520/https://github.com/python/cpython/pull/98862
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

gh-98852: Add extra type check to avoid a bug with parameterizing gen… #98862

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Eclips4
Copy link
Contributor

@Eclips4 Eclips4 commented Oct 29, 2022 •

Copy link
Member

@sobolevn sobolevn left a comment

You would need to:

  1. Add NEWS, consider using blurb CLI or online services. See news CI job logs
  2. Add tests: at least the example from the original bug report. But, I like when there are lots of tests :)

@gvanrossum gvanrossum removed their request for review Oct 29, 2022
@Eclips4
Copy link
Contributor Author

Eclips4 commented Oct 30, 2022 •

I find only one way how to write test for it:

class BaseCallableTests:
    ...
    def test_determine_new_args(self):
        Callable = self.Callable
        T = TypeVar("T")
        P = TypeVar("P")

        class C(Generic[T]): ...

        S = Callable[[C], P]
        U = S[T]
        if self.Callable is collections.abc.Callable:
            self.assertEqual(U, Callable[[C[T]], T])
        else:
            self.assertEqual(U, Callable[[C], T])
    ...

What u think about this?
And i have one question,

from typing import TypeVar, Generic
from collections.abc import Callable
from typing import Callable as TypingCallable


T = TypeVar("T")
P = TypeVar("P")
Z = TypeVar("Z")

class C(Generic[Z]): ...

S = Callable[[C], P]
U = S[T]
U
> collections.abc.Callable[[__main__.C[~Z]], ~T]
S_T = TypingCallable[[C], P]
U_T = S_T[T]
U_T
> typing.Callable[[__main__.C], ~T]

Is it okay?

@sobolevn
Copy link
Member

sobolevn commented Oct 30, 2022

It does not look right that two callables have different results.

Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants