Skip to content

Conversation

@Eclips4
Copy link
Member

@Eclips4Eclips4 commented Oct 29, 2022

Copy link
Member

@sobolevnsobolevn 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 :)

@gvanrossumgvanrossum removed their request for review October 29, 2022 22:50
@Eclips4
Copy link
MemberAuthor

Eclips4 commented Oct 30, 2022

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

classBaseCallableTests: ... deftest_determine_new_args(self): Callable=self.CallableT=TypeVar("T") P=TypeVar("P") classC(Generic[T]): ... S=Callable[[C], P] U=S[T] ifself.Callableiscollections.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,

fromtypingimportTypeVar, Genericfromcollections.abcimportCallablefromtypingimportCallableasTypingCallableT=TypeVar("T") P=TypeVar("P") Z=TypeVar("Z") classC(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
MemberAuthor

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 freeto 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

@Eclips4@sobolevn@JelleZijlstra@bedevere-bot@AlexWaygood