Skip to content

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

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

Closed
wants to merge 2 commits into from
Closed

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

wants to merge 2 commits into from

Conversation

Eclips4
Copy link
Member

@Eclips4 Eclips4 commented Oct 29, 2022

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 October 29, 2022 22:50
@Eclips4
Copy link
Member 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

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

@Eclips4
Copy link
Member Author

Eclips4 commented Nov 1, 2022

I think, problem was solved in this PR: #98952
But, question about collections.abc.Callable and typing.Callable still relevant.

@JelleZijlstra
Copy link
Member

Closing in favor of #98952. I can't reproduce the Callable difference on current main:

Python 3.12.0a1+ (heads/pep688v2-dirty:007fdc1153, Nov  7 2022, 06:50:30) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 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], ~T]
>>> S_T = TypingCallable[[C], P]
>>> U_T = S_T[T]
>>> U_T
typing.Callable[[__main__.C], ~T]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants