Skip to content

[MNT]: macOS backend uses un-prefixed class names #31813

Open

Description

@iccir

Summary

Currently, the macOS backend defines the following four Objective-C classes:

Name Superclass Python Owner
Window NSWindow FigureManager
View NSView FigureCanvas
MatplotlibAppDelegate NSObject -
NavigationToolbar2Handler NSObject NavigationToolbar2

Officially, per Apple Conventions: "your own classes should use three-letter prefixes".

In practice, un-prefixed names like "Window" or "View" are commonly used inside of application code. Inside of framework code, however, they would cause naming conflicts.

The macOS matplotlib backend is an unusual hybrid of a Python framework that then masquerades as an app. As such, it probably makes sense to prefix our classes (either with a standard three-letter abbreviation like MPL or with a full-name prefix like "Matplotlib").

That said, the un-prefixed names seemingly haven't conflicted with anything in over a decade.

Opinions?

Proposed fix

No response

Activity

  1. QuLogic commented on Jun 16, 2026

    @QuLogic
    Member

    I don't think this is really API that we expose otherwise, so we are probably free to rename it at any point. I don't know if there's really a strong impetus to do the change, though.

  2. iccir commented on Jun 16, 2026

    @iccir
    ContributorAuthor

    @QuLogic - The issue isn't that we expose the API, it's that it could conflict with other frameworks or apps. Right now, if the Python process running matplotlib loads some other executable code with a class called "Window", you will see this:

    Class Window is implemented in both /path/to/Foo.framework and
    /path/to/_macosx.cpython-314-darwin.so. One of the two will be used. Which one is undefined.
    

    If you are writing an Obj-C application, it's fine to not use a prefix (although technically it's in violation of Apple's guidelines). However, anything loadable into a process should be prefixed with two letters if you are Apple, or three letters if you are anyone else.

    Note that there's a few historic outliers, WebKit use to use the "Web" prefix before moving to "WK".

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions