-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix type annotation for plt.subplot_mosaic #29893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@github-actions
github-actions
bot
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
What is The reason for this change? Do you have any particular use case? At least when writing out the spec explicitly, I'd want users to use lists. I rather consider the general support of sequences an implementation detail.
Set up:
repos/repro-mpl$ python -m venv venv repos/repro-mpl$ . venv/bin/activate (venv) repos/repro-mpl$ pip install mypy matplotlib (venv) repos/repro-mpl$ mypy --version mypy 1.15.0 (compiled: yes) (venv) repos/repro-mpl$ python -c 'import matplotlib; print(matplotlib.__version__)' 3.10.1 (venv) repos/repro-mpl$ python --version Python 3.10.16
This is what I was trying to solve:
(venv) repos/repro-mpl$ cat foo.py import matplotlib.pyplot as plt mosaic = [["a"], ["b"]] fig, axes = plt.subplot_mosaic(mosaic) (venv) repos/repro-mpl$ mypy foo.py foo.py:3: error: Argument 1 to "subplot_mosaic" has incompatible type "list[list[str]]"; expected "Sequence[HashableList[str]]" [arg-type] Found 1 error in 1 file (checked 1 source file)
Evidently, this PR as of 4b7038d does not fix this yet...
Edit: here's pyright's error message:
(venv) repos/repro-mpl$ pyright foo.py * Install prebuilt node (23.11.0) ..... done. /home/ec2-user/repos/repro-mpl/foo.py /home/ec2-user/repos/repro-mpl/foo.py:3:13 - error: No overloads for "subplot_mosaic" match the provided arguments (reportCallIssue) /home/ec2-user/repos/repro-mpl/foo.py:3:32 - error: Argument of type "list[list[str]]" cannot be assigned to parameter "mosaic" of type "Sequence[HashableList[Hashable]]" in function "subplot_mosaic" "list[list[str]]" is not assignable to "Sequence[HashableList[Hashable]]" Type parameter "_T_co@Sequence" is covariant, but "list[str]" is not a subtype of "HashableList[Hashable]" "list[str]" is not assignable to "list[Hashable | HashableList]" Type parameter "_T@list" is invariant, but "str" is not the same as "Hashable | HashableList" Consider switching from "list" to "Sequence" which is covariant (reportArgumentType) 2 errors, 0 warnings, 0 informations
With b743a81
(venv) repos/repro-mpl$ mypy foo.py Success: no issues found in 1 source file (venv) repos/repro-mpl$ pyright foo.py 0 errors, 0 warnings, 0 informations
With the changes in b743a81, pyright says there are 3 fewer errors than before (7386 vs 7389)
$ pyright venv/lib/python3.10/site-packages/matplotlib
7386 errors, 33 warnings, 0 informations
How can/should I test the implication of this change on the rest of repo? I was not able to set up a dev env, even in CodeSpaces. Happy to try again...
Ok thanks for the clarification. I suspect that you're barking up the wrong tree and instead the TypeVar _HT
used in HashableList
might need to be declared covariant. But I'm not that much in to typing maybe @QuLogic can help here.
As for the dev setup, the description is here: https://matplotlib.org/devdocs/devel/development_setup.html Have you tried to follow that?
Yes, I followed it but can't get an editable install.
After clicking on the "Create codespace" button and waiting a few minutes, here's what I get in the Terminal:
(base) @gshiba ➜ /workspaces/matplotlib (main) $ conda activate mpl-dev (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -c 'import matplotlib; print(matplotlib.__file__)' /home/codespace/.local/lib/python3.12/site-packages/matplotlib/__init__.py (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -m pip install --verbose --no-build-isolation --editable ".[dev]" ... ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. seaborn 0.13.2 requires matplotlib!=3.6.1,>=3.4, but you have matplotlib 0.1.0.dev52310+g7e997ae which is incompatible. Successfully installed matplotlib-0.1.0.dev52310+g7e997ae meson-python-0.16.0 (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -c 'import matplotlib; print(matplotlib.__file__)' Traceback (most recent call last): ... ImportError: /workspaces/matplotlib/build/cp312/src/_path.cpython-312-x86_64-linux-gnu.so: undefined symbol: _ZN3agg10curve3_div4initEdddddd
Full traceback
👋 Welcome to Codespaces! You are on our default image. - It includes runtimes and tools for Python, Node.js, Docker, and more. See the full list here: https://aka.ms/ghcs-default-image - Want to use a custom image instead? Learn more here: https://aka.ms/configure-codespace 🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1). 📝 Edit away, run your app as usual, and we'll automatically make it available for you to access. (base) @gshiba ➜ /workspaces/matplotlib (main) $ conda activate mpl-dev (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -c 'import matplotlib; print(matplotlib.__file__)' /home/codespace/.local/lib/python3.12/site-packages/matplotlib/__init__.py (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -m pip install --verbose --no-build-isolation --editable ".[dev]" Using pip 25.0.1 from /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages/pip (python 3.12) Obtaining file:///workspaces/matplotlib Running command Checking if build backend supports build_editable Checking if build backend supports build_editable ... done Running command Preparing editable metadata (pyproject.toml) + meson setup /workspaces/matplotlib /workspaces/matplotlib/build/cp312 -Dbuildtype=release -Db_ndebug=if-release -Db_vscrt=md --native-file=/workspaces/matplotlib/build/cp312/meson-python-native-file.ini The Meson build system Version: 1.7.1 Source dir: /workspaces/matplotlib Build dir: /workspaces/matplotlib/build/cp312 Build type: native build Program python3 found: YES (/home/codespace/micromamba/envs/mpl-dev/bin/python3) Project name: matplotlib Project version: 0.1.0.dev52310+g7e997ae C compiler for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc (gcc 13.3.0 "x86_64-conda-linux-gnu-cc (conda-forge gcc 13.3.0-2) 13.3.0") C linker for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc ld.bfd 2.43 C++ compiler for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-c++ (gcc 13.3.0 "x86_64-conda-linux-gnu-c++ (conda-forge gcc 13.3.0-2) 13.3.0") C++ linker for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-c++ ld.bfd 2.43 Host machine cpu family: x86_64 Host machine cpu: x86_64 Program python found: YES (/home/codespace/micromamba/envs/mpl-dev/bin/python) Found pkg-config: YES (/home/codespace/micromamba/envs/mpl-dev/bin/pkg-config) 0.29.2 Run-time dependency python found: YES 3.12 Run-time dependency pybind11 found: YES 2.13.6 Downloading freetype-2.6.1 source from https://download.savannah.gnu.org/releases/freetype/freetype-old/freetype-2.6.1.tar.gz Executing subproject freetype-2.6.1 freetype-2.6.1| Project name: freetype2 freetype-2.6.1| Project version: 2.6.1 freetype-2.6.1| C compiler for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc (gcc 13.3.0 "x86_64-conda-linux-gnu-cc (conda-forge gcc 13.3.0-2) 13.3.0") freetype-2.6.1| C linker for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc ld.bfd 2.43 freetype-2.6.1| Has header "unistd.h" : YES freetype-2.6.1| Has header "fcntl.h" : YES freetype-2.6.1| Has header "stdint.h" : YES freetype-2.6.1| Configuring ftconfig.h using configuration freetype-2.6.1| Configuring ftoption.h using configuration freetype-2.6.1| Build targets in project: 2 freetype-2.6.1| Subproject freetype-2.6.1 finished. Downloading qhull source from https://github.com/qhull/qhull/archive/v8.0.2/qhull-8.0.2.tar.gz Executing subproject qhull qhull| Project name: qhull qhull| Project version: 8.0.2 qhull| C compiler for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc (gcc 13.3.0 "x86_64-conda-linux-gnu-cc (conda-forge gcc 13.3.0-2) 13.3.0") qhull| C linker for the host machine: /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-cc ld.bfd 2.43 qhull| Build targets in project: 3 qhull| Subproject qhull finished. Run-time dependency dl found: YES Configuring _version.py using configuration Program /workspaces/matplotlib/tools/generate_matplotlibrc.py found: YES (/workspaces/matplotlib/tools/generate_matplotlibrc.py) Build targets in project: 12 matplotlib 0.1.0.dev52310+g7e997ae Subprojects freetype-2.6.1: YES qhull : YES User defined options Native files : /workspaces/matplotlib/build/cp312/meson-python-native-file.ini b_ndebug : if-release b_vscrt : md buildtype : release Found ninja-1.12.1 at /home/codespace/micromamba/envs/mpl-dev/bin/ninja + /home/codespace/micromamba/envs/mpl-dev/bin/ninja [1/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_trans_affine.cpp.o [2/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_vcgen_contour.cpp.o [3/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_bezier_arc.cpp.o [4/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_vcgen_dash.cpp.o [5/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_curves.cpp.o [6/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_image_filters.cpp.o [7/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftbbox.c.o [8/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftbdf.c.o [9/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftcid.c.o [10/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftbitmap.c.o [11/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_vcgen_stroke.cpp.o [12/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftfntfmt.c.o [13/91] Compiling C++ object extern/agg24-svn/libagg.a.p/src_agg_vpgen_segmentator.cpp.o [14/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftfstype.c.o [15/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftgasp.c.o [16/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftgxval.c.o [17/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftinit.c.o [18/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftglyph.c.o [19/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftmm.c.o [20/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftlcdfil.c.o [21/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftpatent.c.o [22/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftotval.c.o [23/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_autofit_autofit.c.o [24/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftsynth.c.o [25/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftpfr.c.o [26/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftsystem.c.o [27/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftbase.c.o [28/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_fttype1.c.o [29/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftwinfnt.c.o [30/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftstroke.c.o [31/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_bzip2_ftbzip2.c.o [32/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_lzw_ftlzw.c.o [33/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_bdf_bdf.c.o [34/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_cache_ftcache.c.o [35/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_cid_type1cid.c.o [36/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_pcf_pcf.c.o [37/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_gzip_ftgzip.c.o [38/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_cff_cff.c.o [39/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_pshinter_pshinter.c.o [40/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_psaux_psaux.c.o [41/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_psnames_psnames.c.o [42/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_pfr_pfr.c.o [43/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_raster_raster.c.o [44/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_smooth_smooth.c.o [45/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_base_ftdebug.c.o [46/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_winfonts_winfnt.c.o [47/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_type42_type42.c.o [48/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_type1_type1.c.o [49/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_sfnt_sfnt.c.o [50/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_geom_r.c.o [51/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_geom2_r.c.o [52/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_global_r.c.o [53/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_mem_r.c.o [54/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_libqhull_r.c.o [55/91] Compiling C object subprojects/freetype-2.6.1/libfreetype.a.p/src_truetype_truetype.c.o In file included from ../../subprojects/freetype-2.6.1/src/truetype/truetype.c:25: ../../subprojects/freetype-2.6.1/src/truetype/ttgload.c: In function 'load_truetype_glyph': ../../subprojects/freetype-2.6.1/src/truetype/ttgload.c:1455:22: warning: storing the address of local variable 'inc_stream' in 'loader_405(D)->stream' [-Wdangling-pointer=] 1455 | loader->stream = &inc_stream; | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~ ../../subprojects/freetype-2.6.1/src/truetype/ttgload.c:1392:21: note: 'inc_stream' declared here 1392 | FT_StreamRec inc_stream; | ^~~~~~~~~~ ../../subprojects/freetype-2.6.1/src/truetype/ttgload.c:1379:35: note: 'loader' declared here 1379 | load_truetype_glyph( TT_Loader loader, | ~~~~~~~~~~~^~~~~~ [56/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_random_r.c.o [57/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_poly_r.c.o [58/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_io_r.c.o [59/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_usermem_r.c.o [60/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_qset_r.c.o [61/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_userprintf_rbox_r.c.o [62/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_rboxlib_r.c.o [63/91] Linking static target extern/agg24-svn/libagg.a /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-ar: extern/agg24-svn/libagg.a.p/src_agg_bezier_arc.cpp.o: plugin needed to handle lto object [64/91] Linking static target subprojects/freetype-2.6.1/libfreetype.a /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-ar: subprojects/freetype-2.6.1/libfreetype.a.p/src_autofit_autofit.c.o: plugin needed to handle lto object [65/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_userprintf_r.c.o [66/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_user_r.c.o [67/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_poly2_r.c.o [68/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_merge_r.c.o [69/91] Compiling C object subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_stat_r.c.o [70/91] Linking static target subprojects/qhull-8.0.2/libqhull_r.a /home/codespace/micromamba/envs/mpl-dev/bin/x86_64-conda-linux-gnu-ar: subprojects/qhull-8.0.2/libqhull_r.a.p/src_libqhull_r_geom2_r.c.o: plugin needed to handle lto object [71/91] Compiling C++ object src/_c_internal_utils.cpython-312-x86_64-linux-gnu.so.p/_c_internal_utils.cpp.o [72/91] Compiling C++ object src/ft2font.cpython-312-x86_64-linux-gnu.so.p/ft2font.cpp.o [73/91] Compiling C++ object src/_backend_agg.cpython-312-x86_64-linux-gnu.so.p/_backend_agg.cpp.o [74/91] Compiling C++ object src/_image.cpython-312-x86_64-linux-gnu.so.p/_image_wrapper.cpp.o [75/91] Compiling C++ object src/_image.cpython-312-x86_64-linux-gnu.so.p/py_converters.cpp.o [76/91] Compiling C++ object src/ft2font.cpython-312-x86_64-linux-gnu.so.p/ft2font_wrapper.cpp.o [77/91] Compiling C++ object src/_qhull.cpython-312-x86_64-linux-gnu.so.p/_qhull_wrapper.cpp.o [78/91] Compiling C++ object src/_backend_agg.cpython-312-x86_64-linux-gnu.so.p/_backend_agg_wrapper.cpp.o [79/91] Compiling C++ object src/_tkagg.cpython-312-x86_64-linux-gnu.so.p/_tkagg.cpp.o [80/91] Compiling C++ object src/_path.cpython-312-x86_64-linux-gnu.so.p/_path_wrapper.cpp.o [81/91] Linking target src/_c_internal_utils.cpython-312-x86_64-linux-gnu.so [82/91] Compiling C++ object src/_tri.cpython-312-x86_64-linux-gnu.so.p/tri__tri.cpp.o [83/91] Linking target src/_backend_agg.cpython-312-x86_64-linux-gnu.so [84/91] Compiling C++ object src/_tri.cpython-312-x86_64-linux-gnu.so.p/tri__tri_wrapper.cpp.o [85/91] Linking target src/ft2font.cpython-312-x86_64-linux-gnu.so [86/91] Generating lib/matplotlib/mpl-data/matplotlibrc with a custom command [87/91] Linking target src/_path.cpython-312-x86_64-linux-gnu.so [88/91] Linking target src/_image.cpython-312-x86_64-linux-gnu.so [89/91] Linking target src/_qhull.cpython-312-x86_64-linux-gnu.so [90/91] Linking target src/_tkagg.cpython-312-x86_64-linux-gnu.so [91/91] Linking target src/_tri.cpython-312-x86_64-linux-gnu.so Preparing editable metadata (pyproject.toml) ... done Requirement already satisfied: contourpy>=1.0.1 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (1.3.1) Requirement already satisfied: cycler>=0.10 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (0.12.1) Requirement already satisfied: fonttools>=4.22.0 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (4.56.0) Requirement already satisfied: kiwisolver>=1.3.1 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (1.4.8) Requirement already satisfied: numpy>=1.23 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (2.2.4) Requirement already satisfied: packaging>=20.0 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (24.2) Requirement already satisfied: pillow>=9 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (11.1.0) Requirement already satisfied: pyparsing>=2.3.1 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (3.2.1) Requirement already satisfied: python-dateutil>=2.7 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (2.9.0.post0) Collecting meson-python<0.17.0,>=0.13.1 (from matplotlib==0.1.0.dev52310+g7e997ae) Obtaining dependency information for meson-python<0.17.0,>=0.13.1 from https://files.pythonhosted.org/packages/91/c0/104cb6244c83fe6bc3886f144cc433db0c0c78efac5dc00e409a5a08c87d/meson_python-0.16.0-py3-none-any.whl.metadata Downloading meson_python-0.16.0-py3-none-any.whl.metadata (4.1 kB) Requirement already satisfied: pybind11!=2.13.3,>=2.13.2 in /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (2.13.6) Requirement already satisfied: setuptools_scm>=7 in /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (8.2.1) Requirement already satisfied: setuptools>=64 in /home/codespace/.local/lib/python3.12/site-packages (from matplotlib==0.1.0.dev52310+g7e997ae) (76.0.0) Requirement already satisfied: meson>=1.2.3 in /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages (from meson-python<0.17.0,>=0.13.1->matplotlib==0.1.0.dev52310+g7e997ae) (1.7.1) Requirement already satisfied: pyproject-metadata>=0.7.1 in /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages (from meson-python<0.17.0,>=0.13.1->matplotlib==0.1.0.dev52310+g7e997ae) (0.9.1) Requirement already satisfied: six>=1.5 in /home/codespace/.local/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib==0.1.0.dev52310+g7e997ae) (1.17.0) Downloading meson_python-0.16.0-py3-none-any.whl (26 kB) Building wheels for collected packages: matplotlib Running command Building editable for matplotlib (pyproject.toml) Building editable for matplotlib (pyproject.toml) ... done Created wheel for matplotlib: filename=matplotlib-0.1.0.dev52310+g7e997ae-cp312-cp312-linux_x86_64.whl size=10377 sha256=aaead17634334704f01882f8294695fe6ea741b5b35982fe4fe66407d613bde5 Stored in directory: /tmp/pip-ephem-wheel-cache-w5zz02zy/wheels/12/a2/a8/efadc28c14fa1750547f26b6cb4f3e357cd1fa0797dc7e1949 Successfully built matplotlib Installing collected packages: meson-python, matplotlib Attempting uninstall: meson-python Found existing installation: meson-python 0.17.1 Uninstalling meson-python-0.17.1: Removing file or directory /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages/meson_python-0.17.1.dist-info/ Removing file or directory /home/codespace/micromamba/envs/mpl-dev/lib/python3.12/site-packages/mesonpy/ Successfully uninstalled meson-python-0.17.1 Attempting uninstall: matplotlib Found existing installation: matplotlib 3.10.1 Uninstalling matplotlib-3.10.1: Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/__pycache__/pylab.cpython-312.pyc Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/matplotlib-3.10.1.dist-info/ Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/matplotlib/ Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/mpl_toolkits/axes_grid1/ Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/mpl_toolkits/axisartist/ Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/mpl_toolkits/mplot3d/ Removing file or directory /home/codespace/.local/lib/python3.12/site-packages/pylab.py Successfully uninstalled matplotlib-3.10.1 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. seaborn 0.13.2 requires matplotlib!=3.6.1,>=3.4, but you have matplotlib 0.1.0.dev52310+g7e997ae which is incompatible. Successfully installed matplotlib-0.1.0.dev52310+g7e997ae meson-python-0.16.0 (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $ python -c 'import matplotlib; print(matplotlib.__file__)' Traceback (most recent call last): File "<string>", line 1, in <module> File "/workspaces/matplotlib/lib/matplotlib/__init__.py", line 161, in <module> from . import _api, _version, cbook, _docstring, rcsetup File "/workspaces/matplotlib/lib/matplotlib/rcsetup.py", line 29, in <module> from matplotlib.colors import Colormap, is_color_like File "/workspaces/matplotlib/lib/matplotlib/colors.py", line 57, in <module> from matplotlib import _api, _cm, cbook, scale, _image File "/workspaces/matplotlib/lib/matplotlib/scale.py", line 39, in <module> from matplotlib.ticker import ( File "/workspaces/matplotlib/lib/matplotlib/ticker.py", line 144, in <module> from matplotlib import transforms as mtransforms File "/workspaces/matplotlib/lib/matplotlib/transforms.py", line 49, in <module> from matplotlib._path import affine_transform, count_bboxes_overlapping_bbox ImportError: /workspaces/matplotlib/build/cp312/src/_path.cpython-312-x86_64-linux-gnu.so: undefined symbol: _ZN3agg10curve3_div4initEdddddd (mpl-dev) @gshiba ➜ /workspaces/matplotlib (main) $
... but this is off topic. Shall I create a separate issue for this?
Your setup is broken, the issue is hat you have stuff in /home/codespace/.local/lib/python3.12
. This can e.g. happen if you have at some point installed something with pip install --user
. Such installed packages are global for your user, i.e. included in every python 3.12 interperter you run. This breaks the separatation you get from environments. Generally you should not have anything in local/lib if you work with environements.
In the general case, I would tend to agree that on parameters, using Sequence
is often better than over-specifying as list
. A general principle in typing is to be permissive on parameters and restrictive on returns where possible.
However, in this specific case, this parameter gets a little harder to deal with in particular because str
counts as a Sequence
, which complicates some things. Not necessarily impossible to overcome, but I'd want to think on it at least a bit more.
What I'm confused by, though, is in this example I think that the distinction between Sequence
and list
should be inconsequential, as list
is being used... so I'm not clear why it is failing the type check to begin with.
Your setup is broken, the issue is hat you have stuff in
/home/codespace/.local/lib/python3.12
. This can e.g. happen if you have at some point installed something withpip install --user
. Such installed packages are global for your user, i.e. included in every python 3.12 interperter you run. This breaks the separatation you get from environments. Generally you should not have anything in local/lib if you work with environements.
That is not the case here; it is a bug in our setup for conda, or conda-forge itself. Please see #29852.
What I'm confused by, though, is in this example I think that the distinction between Sequence and list should be inconsequential, as list is being used... so I'm not clear why it is failing the type check to begin with.
The problem is in expected vs inferred type of the inner list:
- the existing code expects the inner list to be:
HashableList: TypeAlias = list[_HT | "HashableList[_HT]"]
- the inferred type of
[["a"], ["b"]]
islist[list[str]]
which means the inner list is strictly a list of_HT
.
Demo:
# foo.py import matplotlib.pyplot as plt inferred_mosaic = [["a"], ["b"]] reveal_type(inferred_mosaic) fig, axes = plt.subplot_mosaic(inferred_mosaic) # type error explicit_mosaic: list[list[str | list]] = [["a"], ["b"]] reveal_type(explicit_mosaic) fig, axes = plt.subplot_mosaic(explicit_mosaic) # type ok
$ pyright foo.py /Users/ec2-user/repos/matplotlib-test/foo.py /Users/ec2-user/repos/matplotlib-test/foo.py:5:13 - information: Type of "inferred_mosaic" is "list[list[str]]" /Users/ec2-user/repos/matplotlib-test/foo.py:6:13 - error: No overloads for "subplot_mosaic" match the provided arguments (reportCallIssue) /Users/ec2-user/repos/matplotlib-test/foo.py:6:32 - error: Argument of type "list[list[str]]" cannot be assigned to parameter "mosaic" of type "list[HashableList[Hashable]]" in function "subplot_mosaic" "list[list[str]]" is not assignable to "list[HashableList[Hashable]]" Type parameter "_T@list" is invariant, but "list[str]" is not the same as "HashableList[Hashable]" Consider switching from "list" to "Sequence" which is covariant (reportArgumentType) /Users/ec2-user/repos/matplotlib-test/foo.py:9:13 - information: Type of "explicit_mosaic" is "list[list[str | list[Unknown]]]" 2 errors, 0 warnings, 2 informations
... and this can be resolved by changing the type from list
to Sequence
(this PR) which makes the inner (and outer) list immutable.
Uh oh!
There was an error while loading. Please reload this page.
PR summary
Fixes the following type error:
PR checklist