Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

type[TypeVar] not checked properly with upper bound #14755

Closed
@sterliakov

Description

@sterliakov

Bug Report

When checking a function with argument oftype[SomeTypeVar], class attributes are considered missing.

To Reproduce

fromtypingimportClassVar,Type,TypeVar,castclassOne:PATTERN:ClassVar[str]=r"^([a-z]{3})$"classTwo:PATTERN:ClassVar[str]=r"^([0-9]{3})$"_T=TypeVar("_T",bound=One|Two)deffoo(result_type:Type[_T])->_T:result_type.PATTERN# E: "Type[_T]" has no attribute "PATTERN"  [attr-defined]returncast(_T,result_type())foo(One)foo(Two)

This doesn't depend onClassVar and works withFinal or plainstr as well.

Gist:https://mypy-play.net/?mypy=master&python=3.10&gist=2d769a9767898e71431e59df1c2f8488

Expected Behavior

No errors (let's ignorecast for now, it's another unrelated issue).

Actual Behavior

main.py:12: error: "Type[_T]" has no attribute "PATTERN"  [attr-defined]Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.0.0 and master
  • Mypy command-line flags: not related
  • Mypy configuration options frommypy.ini (and other config files): not related
  • Python version used: 3.9-3.11, not related

Discovered inthis SO question

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp