New submission from William George <wrgeorge1...@gmail.com>:

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.

----------
components: Library (Lib)
messages: 407005
nosy: pmoody, wrgeorge1983
priority: normal
severity: normal
status: open
title: Type annotations needed for convenience functions in ipaddress module
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45900>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to