Skip to content

Subclassing Class having type Any #10848

Closed
@hardikkat24

Description

@hardikkat24

Bug Report

Subclassing class with class having type Any results in abnormal behaviour.

To Reproduce

  1. Write a function having a class A which subclasses an element of type Any. Then subclass the A to create B. Subclass B to create C.
from typing import Any
import x  # this will be of type Any as ignore-missing-imports is True

class A(x):
    def __init__(self, *args, **kwargs):
        # type: (*Any, **Any) -> None
        self.a = 1

class B(A):
    pass

class C(B):
    pass

a = A()
b = B()
c = C()

reveal_type(a)
reveal_type(b)
reveal_type(c)

  1. Run mypy checks on this code.

Expected Behavior

The output should have been:

../../t.py:19: note: Revealed type is 't.A'
../../t.py:20: note: Revealed type is 't.B'
../../t.py:21: note: Revealed type is 't.C'

Actual Behavior

../../t.py:19: note: Revealed type is 't.A'
../../t.py:20: note: Revealed type is 't.A'
../../t.py:21: note: Revealed type is 't.A'

(Write what happened.)

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: Only passed the config file
  • Mypy configuration options from mypy.ini (and other config files):
[mypy]
python_version = 2.7

# Ignore if stubs of a third-party library is missing.
ignore_missing_imports = True

# Enables showing the error code along with error.
show_error_codes = True

follow_imports = silent

# Directory path where MyPy searches for stubs of third-party libraries.
mypy_path = stubs/

namespace_packages = True
explicit_package_bases = True

# Enabling the strict type checks.
strict = True
  • Python version used: Python 2.7.18
  • Operating system and version: Ubuntu 20.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions