Skip to content
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

Semantic highlight is wrong for some matplotlib classes #6105

Closed
alex180500 opened this issue Jul 8, 2024 · 5 comments
Closed

Semantic highlight is wrong for some matplotlib classes #6105

alex180500 opened this issue Jul 8, 2024 · 5 comments
Assignees

Comments

@alex180500
Copy link

alex180500 commented Jul 8, 2024

Given the following code

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

print(ax.transData.transform((0, 0)))
print(fig.transFigure.transform((0, 0)))

image

Why are the two print statement of different colors?

Pylance: v2024.6.1
VS Code: 1.91.0

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jul 8, 2024
@debonte
Copy link
Contributor

debonte commented Jul 8, 2024

I'm unable to reproduce this and the semantic token type, modifiers, and textmate scopes on these two calls appear to be the same.

Some questions for you:

  1. Have you tried disabling your other extensions temporarily? Perhaps one of them is also providing semantic tokenization?
  2. Which theme are you using? It's possible that we could repro it using the same theme, but given what I said about the token type, etc above, that seems unlikely to me.
  3. What version of matplotlib are you using? I'm using 3.9.1.

@debonte debonte added waiting for user response Requires more information from user needs repro Issue has not been reproduced yet and removed needs repro Issue has not been reproduced yet labels Jul 8, 2024
@rchiodo
Copy link
Contributor

rchiodo commented Jul 8, 2024

I can reproduce it with matplotlib 3.8. The type of ax is Any so the overload for print is different. With 3.9.1, the type of ax is Axes and both prints are the same.

@debonte debonte removed the waiting for user response Requires more information from user label Jul 8, 2024
@debonte
Copy link
Contributor

debonte commented Jul 8, 2024

I see. It's because ndarray (the return type of fig.transFigure.transform declares a __str__ method. So we're trying to tell the user that there's custom print behavior in play here.

Here's a repro without matplotlib:

from typing import Any

class Foo:
    def __str__(self):
        return "foo"

def returns_any() -> Any: ...

foo = Foo()
print(foo) # Has `overridden` semantic token modifier
foo = returns_any()
print(foo) # Does not have `overridden` modifier

@rchiodo
Copy link
Contributor

rchiodo commented Jul 9, 2024

This issue should be by design then. The different colors are because the two prints are semantically different. Well based on the types returned by matplotlib. They would be the same once updating to a newer matplotlib.

@bschnurr
Copy link
Member

bschnurr commented Jul 9, 2024

closing as designed.

@bschnurr bschnurr closed this as completed Jul 9, 2024
@rchiodo rchiodo added by design and removed needs repro Issue has not been reproduced yet labels Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants