CQ002: HasTypeHints

Overview

Property Value
ID CQ002
Name HasTypeHints
Group code-quality
Severity NOTE

Description

Checks for a py.typed marker file indicating the package provides type hints.

PEP 561 defines how packages can indicate they include type information. This enables:

  • Better IDE autocomplete
  • Static type checking with mypy/pyright
  • Improved developer experience

What it checks

The check looks for py.typed file in:

  • src/{package_name}/py.typed (src layout)
  • {package_name}/py.typed (flat layout)

How to fix

Create an empty py.typed marker file:

touch src/my_package/py.typed

Include in package

Ensure the file is included in your distribution. Most build backends include it automatically, but verify in pyproject.toml:

[tool.hatch.build.targets.wheel]
packages = ["src/my_package"]

Add type annotations

Once you have py.typed, add type hints to your code:

def greet(name: str) -> str:
    """Greet someone by name."""
    return f"Hello, {name}!"

Test with mypy

pip install mypy
mypy src/my_package

Why NOTE severity?

This check is a NOTE because:

  • Type hints are optional in Python
  • Some packages may not benefit from typing
  • Adding types requires ongoing maintenance

Configuration

Skip this check

[tool.pycmdcheck]
skip = ["CQ002"]

CLI

pycmdcheck --skip CQ002