This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Type annotations needed for convenience functions in ipaddress module
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, pmoody, wrgeorge1983
Priority: normal Keywords: patch

Created on 2021-11-25 15:53 by wrgeorge1983, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29778 closed wrgeorge1983, 2021-11-25 16:15
Messages (2)
msg407005 - (view) Author: William George (wrgeorge1983) * Date: 2021-11-25 15:53
The convenience factory functions in the ipaddress module each return one of two types (IPv4Network vs IPv6Network, etc).  Modern code wants to be friendly to either stack, and these functions are great at enabling that, but current implementation blocks type inference for most (all?) IDEs.

Proposal is easy enough, specifying return type of e.g. `Union[IPv4Network, IPv6Network]` for these factory functions.  

I believe the rest of the public interface for this module is unambiguous enough that annotations aren't needed, but if others see value they could be added easily enough.

For some of these there exists a version-independent base class that could be referenced instead of a union, but it's not clear to me how well IDEs will actually honor such an annotation referencing an internal class (single-underscore).  My limited testing of that didn't work well and there's no such base class for the Interface classes anyway. 

PR for this incomming.
msg407009 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2021-11-25 17:04
Typing for stdlib is provided by https://github.com/python/typeshed
CPython policy discourages embedded typing declarations.
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 90058
2021-11-25 17:04:06asvetlovsetstatus: open -> closed

nosy: + asvetlov
messages: + msg407009

resolution: rejected
stage: patch review -> resolved
2021-11-25 16:15:49wrgeorge1983setkeywords: + patch
stage: patch review
pull_requests: + pull_request28015
2021-11-25 15:53:03wrgeorge1983create