Skip to content

[common] Add {:r} repr formatter for TypeSafeIndex and Identifier - #24936

Open
castor639 wants to merge 1 commit into
RobotLocomotion:masterfrom
castor639:typesafeindex-repr-formatter
Open

[common] Add {:r} repr formatter for TypeSafeIndex and Identifier#24936
castor639 wants to merge 1 commit into
RobotLocomotion:masterfrom
castor639:typesafeindex-repr-formatter

Conversation

@castor639

@castor639 castor639 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Default fmt output remains the bare integer. The new {:r} specifier prints a typed representation (e.g. FooIndex(0), FooId(1)) using NiceTypeName. Also teach NiceTypeName to canonicalize TypeSafeIndex the same way it already does for Identifier.

Fixes #24262.


This change is Reviewable

Default fmt output remains the bare integer. The new {:r} specifier
prints a typed representation (e.g. FooIndex(0), FooId(1)) using
NiceTypeName. Also teach NiceTypeName to canonicalize TypeSafeIndex
the same way it already does for Identifier.

Fixes RobotLocomotion#24262.
@SeanCurtis-TRI SeanCurtis-TRI added the release notes: feature This pull request contains a new feature label Sep 1, 2026
@SeanCurtis-TRI SeanCurtis-TRI self-assigned this Sep 1, 2026
@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

+(release notes: feature) +a:@SeanCurtis-TRI for feature review.

@SeanCurtis-TRI SeanCurtis-TRI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all makes sense as far as it goes. I think we might want to discuss a bit more if this is exactly the format string we want -- see the questions raised in the linked issue. We'll stall until that discussion is definitively resolved.

@SeanCurtis-TRI reviewed 7 files and all commit messages, and made 2 comments.
Reviewable status: 1 unresolved discussion, LGTM missing from assignee SeanCurtis-TRI(platform), needs at least two assigned reviewers (waiting on castor639).


common/identifier.h line 293 at r1 (raw file):

  }

 private:

nit: This goes against drake style guide. The member should neither be private nor should it have a trailing underscore.

@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

@drake-jenkins-bot test this please

@SeanCurtis-TRI

Copy link
Copy Markdown
Contributor

@drake-jenkins-bot retest this please

@tyler-yankee

Copy link
Copy Markdown
Contributor

@drake-jenkins-bot retest this please

@tyler-yankee

Copy link
Copy Markdown
Contributor

Woops, it's just docstrings failing CI, I thought we had bad timing on the infrastructure issue yesterday. Sorry about that!

@jwnimmer-tri jwnimmer-tri self-assigned this Sep 3, 2026

@jwnimmer-tri jwnimmer-tri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwnimmer-tri made 1 comment.
Reviewable status: 1 unresolved discussion, LGTM missing from assignees jwnimmer-tri(platform),SeanCurtis-TRI(platform) (waiting on SeanCurtis-TRI).


common/identifier.h line 293 at r1 (raw file):

Previously, SeanCurtis-TRI (Sean Curtis) wrote…

nit: This goes against drake style guide. The member should neither be private nor should it have a trailing underscore.

It's conventional for format specs to be private (see fmt_eigen.h, and all upstream fmt formatters).

However, yes, the member field should not be named with trailing underscore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release notes: feature This pull request contains a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Formatter options for TypeSafeIndex and Identifier

4 participants