Skip to content

Types should be promoted by issubclass #2909

@chadrik

Description

@chadrik

I expected types to be promoted to sub-types within an issubclass block, the same as instances within an isinstance block, but type-checking the following code results in the error Type[Vehicle] has no attribute "wheels":

from typing import Type

class Vehicle(object):
    name = ''

class Car(Vehicle):
    wheels = 4

def test_isinstance(x):
    # type: (Vehicle) -> None
    print(x.name)
    if isinstance(x, Car):
        print(x.wheels)

def test_issubclass(x):
    # type: (Type[Vehicle]) -> None
    print(x.name)
    if issubclass(x, Car):
        print(x.wheels)

Is this be possible or am I missing something? I'm testing against the master branch.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions