reportUntypedBaseClass.md

April 8, 2026 · View on GitHub

Overview

reportUntypedBaseClass flags cases where a class inherits from a base class that lacks type information. This diagnostic helps ensure that all base classes are properly typed, improving static analysis and code reliability.

Representative Issues

  • #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings.
  • #5200: Provide a configuration setting to allow users to customize diagnostic rule severities based on the type checking mode.
  • #6300: Exclude unnecessary folders like .venv to improve performance.
  • #1759: Ensure that libraries used in a project include type information or provide stub files.
  • #2912: Use type aliases to explicitly define base classes for subclasses.
  • #3251: Pyright should support namespace packages to align with modern Python packaging techniques.
  • #4367: Ensure comments in TOML files use correct line endings and do not contain unsupported control characters.

Examples

Error:

from untyped_lib import BaseModel  # BaseModel has no type info

class User(BaseModel):  # Base class is untyped
    name: str

Fix — use a typed base class or add a stub:

# Option 1: Install type stubs for the library
# pip install types-untyped-lib

# Option 2: Create a local stub file (untyped_lib.pyi)
# class BaseModel: ...

# Option 3: Use a typed base class directly
class BaseModel:
    pass

class User(BaseModel):  # Base class now has type info
    name: str

Common Fixes & Workarounds

  1. Use base classes that include type information or provide type stubs for third-party libraries.
  2. Use type aliases to explicitly define base classes for subclasses.
  3. Ensure all necessary packages are installed in your environment.
  4. Exclude unnecessary folders from analysis to improve performance.
  5. Review the Pyright configuration documentation for details on configuring or disabling this diagnostic.

See Also