Skip to content

Final nested inside ClassVar results in Any #19607

Open

Description

@hovsater

Bug Report

According to the Python 3.13 ClassVar documentation, ClassVar can be nested within Final, and Final can likewise be nested within ClassVar.

Changed in version 3.13: ClassVar can now be nested in Final, and vice versa.

However, Mypy seems to type-check only the case where ClassVar is nested inside Final, not the reverse.

To Reproduce

https://mypy-play.net/?mypy=latest&python=3.13&flags=strict&gist=996a968ac738badee42e71c23bd5f539

Expected Behavior

Success: no issues found in 1 source file

Actual Behavior

main.py:7: error: Returning Any from function declared to return "int"  [no-any-return]
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: mypy 1.17.1 (compiled: yes)
  • Mypy command-line flags: --strict
  • Python version used: Python 3.13.3

Activity

  1. emmatyping commented on Aug 7, 2025

    @emmatyping
    Member

    Support for the opposite nesting order was added in #18358

    The Python docs state:

    Changed in version 3.13: ClassVar can now be nested in Final and vice versa.

    So we're just missing the vice versa (i.e. ClassVar[Final[...]])

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

    bugmypy got something wrongtopic-finalPEP 591

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions