Skip to content

Use metacode to read comments #20785

Closed
Closed

Description

@pomponchik

Feature

What about to replace the current way of reading machine-readable comments with a ready-made solution: metacode. This will not only simplify the internal implementation of mypy, but also eliminate some bugs of the current scheme.

Pitch

I have 2 linters that respond to the problem in the same line of code: ruff and mypy. Here is my code:

@classmethod
def from_callable(cls, function: Callable[..., Any], raise_exception: bool = False) -> 'SignatureSeriesMatcher':  # noqa: F821 # type: ignore[name-defined]
    ...

If I shut up ruff first and then mypy, I get an error from mypy:

some_file:227: error: Name "SignatureSeriesMatcher" is not defined  [name-defined]

However, if I swap them like this:

# type: ignore[name-defined] # noqa: F821

... the mypy error disappears.

Obviously, mypy does not know how to correctly handle changing the order of machine-readable comments.

This problem can be solved quickly if you use a ready-made solution for reading such comments: metacode. This "out of the box" can read comments arranged in any order.

Activity

  1. A5rocks commented on Feb 12, 2026

    @A5rocks
    Collaborator

    For now, I think we're going to stick to what the Python AST module provides. However, feel free to drop a comment in #12358 about this!

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions