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

Specialized sub-classes of Generic never call __init__ #192

Closed
Milestone
@gvanrossum

Description

@gvanrossum

Seehttp://bugs.python.org/issue26391 .

"""
A specialized sub-class of a generic type never calls__init__ when it is instantiated. See below for an example:

fromtypingimportGeneric,TypeVarT=TypeVar('T')classFoo(Generic[T]):def__init__(self,value:T):self.value=valueBar=Foo[str]foo=Foo('foo')bar=Bar('bar')print(type(foo),end=' ')print(foo.value)print(type(bar),end=' ')print(bar.value)# AttributeError

I would expect Foo[str], Foo[int], etc to be equivalent to Foo at run-time. If this is not the case it might deserve an explicit mention in the docs. At the moment, behaviour is confusing because an instance of Foo is returned that does not have any of its attributes set.
"""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp