Skip to content

Make IPv{4,6}Address.version and max_prefixlen available on classes, not just instances #118710

Closed
@abacabadabacaba

Description

@abacabadabacaba

Feature or enhancement

Proposal:

Sometimes, when there is a function that can operate both on IPv4 and IPv6 addresses, it is convenient to pass it the corresponding type object (either IPv4Address or IPv6Address) as an argument. However, that function cannot access the properties version and max_prefixlen using those type objects, because they only work on instances. This can be worked around by constructing a dummy instance (e.g. t(0).max_prefixlen), but it would be more convenient if those properties could be used on the type object directly (i.e. t.max_prefixlen), because their value doesn't depend on the specific instance, only on the type.

The proposal is to make IPv4Address.version, IPv4Address.max_prefixlen, IPv6Address.version, and IPv6Address.max_prefixlen evaluate to 4, 32, 6, and 128, respectively. Currently, all those expressions evaluate to property descriptors.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions