pybind / pybind/pybind11

Detail: type naming convention

Open
#1,016 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement question
Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

In the pybind11 detail code, we have 3 different kinds of type information:

  1. C++ RTTI: std::type_info
  2. Python's PyTypeObject
  3. pybind11's extended type information: detail::type_info

The variable naming scheme for these 3 kinds of type info objects isn't currently very consistent. type, tinfo, type_info, etc. are used interchangeably for all 3 kinds of type info, which can cause confusion (at least it does for me). And as I've recently found in #1014, it can result in some unfortunate expressions like x.type->type (where the second type isn't a Python-style metatype, it's just a different kind of type object).

I'd like to propose a naming convention for these objects (especially when they are members):

  1. std::type_info: variables named cpptype (already in use, but only partially).
  2. PyTypeObject: pytype.
  3. detail::type_info: it would be nice to rename the type to detail::extended_type (to avoid confusion with std::type_info) and name variables like ext_type or et.

What do you think? Does it make sense or am I just bikeshedding?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the pybind11 detail code and the three type-information forms named in the issue: std::type_info, PyTypeObject, and detail::type_info. Determine whether a naming convention is agreed upon and how broadly it would apply. Done would require a resolved convention and an agreed scope for any renaming.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.