JelleZijlstra / stubdefaulter

Add default values to stubs
Other
10 stars 4 forks source link

Missed default replacements on `__init__` methods of C extension classes #97

Open brianschubert opened 1 week ago

brianschubert commented 1 week ago

stubdefaulter misses replacements on __init__ methods of C extension classes.

For example: python/typeshed#12797 and python/typeshed#12798

It looks like this may be related having signature(cls) != signature(cls.__init__) at runtime:

>>> import inspect, pickle

>>> pickle.Pickler
<class '_pickle.Pickler'>   # backed by _pickle C extension module

>>> inspect.signature(pickle.Pickler)
<Signature (file, protocol=None, fix_imports=True, buffer_callback=None)>

>>> inspect.signature(pickle.Pickler.__init__)
<Signature (self, /, *args, **kwargs)>
brianschubert commented 1 week ago

This also affects replacements for __new__ based on python/typeshed#12796

JelleZijlstra commented 1 week ago

Maybe stubdefaulter should look for a signature on the class when the one on __init__ or __new__ is not informative.