PyO3 / PyO3/pyo3

Add support for defining metaclasses in Rust

Open
#5,958 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

Declaring a metaclass in Rust requires to extend PyType and to adapt the default new implementation (since a metaclass should always allow to create a class in Python).

This would allow for efficient implementation of __instancecheck__ and __subclasscheck__. It would also allow to keep track of information about created classes in Rust instead of storing them as standard attributes on the class which can be modified later.

I am fine doing the changes. I am however open to suggestions as to where to document this.

Specifying a metaclass when defining a class in Rust is out of scope.

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 reading PyType and the default new implementation, then review the existing Rust-side class-definition support. Determine where metaclass support should be documented, as the issue leaves that location open. Done means Rust-defined metaclasses can support class creation, instancecheck, and subclasscheck, while specifying a metaclass when defining a class remains out of scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.