GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: Missing typing for backend_wxagg.py · Issue #26941 · matplotlib/matplotlib

[Bug]: Missing typing for backend_wxagg.py #26941

New issue
Copy link
New issue
Copy link
Open
Open
[Bug]: Missing typing for backend_wxagg.py#26941
Copy link
Labels
topic: typing

Description

@chacabuco
chacabuco
opened on Sep 28, 2023
Issue body actions

Bug summary

with mypy, FigureCanvasWxAgg results in error:

Call to untyped function "FigureCanvasWxAgg" in typed context [no-untyped-call]

Code for reproduction

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

FigureCanvas(None, -1)
# Then run mypy --strict

Actual outcome

Call to untyped function "FigureCanvasWxAgg" in typed context [no-untyped-call]

Expected outcome

No Mypy error

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.8.0

Matplotlib Backend

wxAgg

Python version

3.8.10

Jupyter version

No response

Installation

pip

Activity

  1. oscargus
    added
    topic: typing
    on Sep 28, 2023
  2. oscargus commented on Sep 28, 2023

    @oscargus
    oscargus
    on Sep 28, 2023
    Member
    More actions

    All backends are missing typing (except for the C++-based agg-backend).

  3. ksunden commented on Sep 28, 2023

    @ksunden
    ksunden
    on Sep 28, 2023
    Member
    More actions

    Backends were left out of the initial round of type hints because they are a bit more advanced and we needed to reign in the scope a bit.

    Even the agg one is an empty file, FYI. (There just to make it so that imports aren't flagged)

    While it doesn't help with the constructor call, you should be able to get a reasonable amount of the benefits of type hinting from matplotlib.backend_bases.FigureCanvasBase, which is the shared base class for all figure canvases. The base class is type hinted.

    If you are interested in adding type hints to backends, that would also be welcome.

    For wxagg, this would include type hinting the agg backend, which defines the following methods not found in FigureCanvasBase:

    >>> set(dir(agg))-set(dir(base))
    {
        'print_jpg',
        'print_jpeg',
        '_print_pil',
        'print_tiff',
        'restore_region',
        'print_to_buffer',
        'tostring_rgb',
        '_lastKey',
        'print_tif',
        'print_raw',
        'print_webp',
        'get_renderer',
        'buffer_rgba',
        'print_rgba',
        'print_png',
        'copy_from_bbox',
        'tostring_argb'
    }

    And the following functions are defined which are not defined for either of the base classes (Filtering out things added by the wx Parent):

    >>> set(filter(lambda x: x[0] == x[0].lower() and x[0] != '_', set(dir(wx))-set(dir(base))-set(dir(agg)))
    {'gui_repaint', 'keyvald'}

    These lists are a starting point/hint at the amount of work for this task, but I'd actually suggest running stubgen to get started.

    Note that a full solution would address not only FigureCanvas, but also Renderer, Toolbar-related things, etc. (essentially all classes defined in backend_wx.py, backend_wxagg.py, and backend_agg.py, and at least their public behaviors)
    Functions which do not modify signatures from the base class may be omitted from the stub file.

    I believe all of these to be reasonably well behaved from a type perspective, though it is quite possible docstrings are lacking parameter information (or missing entirely) for these, so may take some digging for someone who has not worked with backends code before (and I'd count myself in that category).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: typing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.