Skip to content

proposal: strconv: Make FormatInt accept any integer type #58407

@misha-ridge

Description

@misha-ridge

Description

  • Change strconv.FormatInt to be a generic that accepts any integer type.
  • Deprecate strconv.FormatUint and suggest to use strconv.FormatInt instead.

Motivation

During a review of a medium-sized codebase I have noticed that there are two causes of typecasts to the arguments of strconv.Format[U]Int: casting integers to a wider type, and casting non-integers (floats, types based on integers). These two cases are hard to distinguish and as a result of the review we had to add a comment to every typecast.

First type of casts (wider-type casts) ought not exist, they are an artifact of Format[U]Int been created before generics. This proposal gets rid of the useless typecasts of first type, leaving only second, meaningful, typecasts in place.

As far as I can tell this proposal does not break backward compatibility, as it makes FormatInt accept strictly more types than before.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions