typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Add stubs for "netiface" package

Open Delgan opened this issue 1 year ago • 9 comments

Hi.

I generated stub files for the netifaces library. Unfortunately, this library is no longer maintained (although still working well). For this reason, I would like to submit type hints to typeshed.

I compared to the types created initially by @jolaf in https://github.com/al45tair/netifaces/issues/39 and it seems to match well.

Delgan avatar Oct 18 '24 18:10 Delgan

PR updated with improved types contributed by @J-M0 here: https://github.com/al45tair/netifaces/pull/77

Delgan avatar Oct 18 '24 18:10 Delgan

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Oct 18 '24 18:10 github-actions[bot]

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Oct 18 '24 19:10 github-actions[bot]

Thanks, good idea!!

jolaf avatar Oct 19 '24 11:10 jolaf

Hey all,

It so happens that I actually revisited these stubs I made a while ago and made some significant improvements, but never published them because I didn't think there was any interest. Is there any way we can integrate them into this?

J-M0 avatar Oct 19 '24 14:10 J-M0

Thanks @J-M0! There's a couple of approaches:

  • We could merge this PR, then you could make another PR with your improvements.
  • You could make a PR to @Delgan's fork with your changes, to get them merged into this PR branch.
  • You could open your own PR against typeshed and replace this one.

If the changes you're making are mostly about expanding the coverage (e.g., adding more types), then I'd advocate for the first one; it's good to start with simpler stubs and make them more comprehensive over time. If you're fixing incorrect types, then it's better to get them right the first time.

JelleZijlstra avatar Oct 19 '24 14:10 JelleZijlstra

@JelleZijlstra, the work I've done is mostly about making the return type for the gateways() function more precise. I also today incorporated @srittau's suggestion to mark constants as Final.

I've pushed my changes here so you can see them: https://github.com/J-M0/netifaces/blob/5dc562a0083b2a24f4fba33257a9b1aa654a3782/netifaces-stubs/init.pyi. Let me know how you think we should proceed.

J-M0 avatar Oct 19 '24 16:10 J-M0

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Oct 19 '24 17:10 github-actions[bot]

Hey @J-M0, thanks for chiming in with additional improvements!

I updated my PR to use PEP 585 and add Final as requested by @srittau. Your implementation of _Gateways looks very interesting. I was wondering how to encode the invariant of the "default" key, but I didn't think the type system could support it.

Delgan avatar Oct 19 '24 17:10 Delgan

@srittau How long would it take for the changes to become available as types-netifaces in pip?

jolaf avatar Oct 21 '24 15:10 jolaf

Packages are built nightly (UTC time).

srittau avatar Oct 21 '24 16:10 srittau