inetaf / netaddr

Network address types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add IP.Valid?

bradfitz opened this issue · comments

We already have IP.IsZero to test whether an IP is valid, at least if you negate it: !ip.IsZero().

But all the other types have a Valid() bool method:

  • IPPort.Valid() bool
  • IPPrefix.Valid() bool
  • IPRange.Valid() bool

So naturally I reached for IP.Valid and it didn't exist.

Add it?

/cc @mdlayher @danderson @josharian

I like symmetry, go for it.

Oh, crap, we named it wrong:

dev:api $ git grep -E 'method.*Valid\('
go1.txt:pkg go/token, method (*Position) IsValid() bool
go1.txt:pkg go/token, method (Pos) IsValid() bool
go1.txt:pkg reflect, method (Value) IsValid() bool
go1.txt:pkg text/scanner, method (*Position) IsValid() bool
go1.txt:pkg text/scanner, method (*Scanner) IsValid() bool

If this is going into std, we should adjust, perhaps earlier.

How about: add IsValid for all 4, but mark the old Valid ones as deprecated so we don't break people's code. But if it moves to std, the Valid ones won't come along.

SGTM. We could also get rid of Valid here eventually as well, there's relatively few users of the package still.

(that is, we could fix downstream users then remove Valid)

No objections to API breakage here. Making IPPrefix an opaque type was much more jarring and even that was pretty easy to fix up.