-
-
Notifications
You must be signed in to change notification settings - Fork 3k
More detailed checking of type objects in stubtest #18251
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
Conversation
This uses checkmember.type_object_type and context to produce better types of type objects.
I figured out a fix for |
I added a test case which I confirmed fails without this MR in place. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable but probably worth running against typeshed again
I ran it against against typeshed. No new errors, and clears the same five as before on 3.9 through 3.14:
|
This uses
checkmember.type_object_type
and context to produce better types of type objects.I did this work while doing a deep dive on
argparse.ArgumentParser.__init__
, which is on the allowlist in typeshed with the note:stubtest doesn't recognise the runtime default (a class) as being compatible with a callback protocol (the stub annotation)
Mypy proper has no problem with this, and after investigation the primary difference seemed to be that stubtest looked up the type of the class and got
type
while Mypy proper usedcheckmember.type_object_type
to convert the class into a callable type. This worked to clearargparse.ArgumentParser.__init__
, but generated all kinds of new errors at first. After some cleanup, I still had about as many new errors as errors fixed. Several of these were an instance of #3737, so I special-cased them to skip the new logic.At this point, this MR clears five allowlist entries from typeshed standard library:
It introduces four new errors:
Of these, I think that:
ctypes.CDLL._func_restype_
is a genuine error in the stubs (we have_func_restype_: ClassVar[_CDataType]
and it should be_func_restype_: ClassVar[type[_CDataType]]
). `ctypes.c_time_t
looks like a genuine error. We havec_time_t: type[c_int32 | c_int64]
which is fine, but the issue is that in the stubsc_int32
andc_int64
are both unique classes and at runtime they're each an alias for one ofc_short
,c_int
,c_long
, orc_longlong
. We can clear it by expanding the union to include those additional types, but I'm 100% certain if that's better or not.unittest.TextTestRunner.resultclass
andunittest.runner.TextTestRunner.resultclass
are the same error. I looked at it for a while and I can't figure out what the issue is. We haveresultclass: _ResultClassType
where that's the type alias:and the runtime default is
TextTestResult
, which hasIt's a complicated set of type aliases and type variables, and I think it's probably likely that there's something real here, but I can't spot it.