Convert Figma logo to code with AI

PyCQA logopydocstyle

docstring style checker

1,107
188
1,107
124

Top Related Projects

13,756

A formatter for Python files

38,772

The uncompromising Python code formatter

3,428

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.

5,286

It's not just a linter that annoys you!

30,822

An extremely fast Python linter and code formatter, written in Rust.

A framework for managing and maintaining multi-language pre-commit hooks.

Quick Overview

PyCQA/pydocstyle is a static analysis tool for checking compliance with Python docstring conventions. It validates docstrings against the style recommendations in PEP 257, helping developers maintain consistent and informative documentation throughout their Python projects.

Pros

  • Improves code quality and readability by enforcing consistent docstring conventions
  • Integrates easily with popular code editors and continuous integration pipelines
  • Customizable through configuration files, allowing teams to define their own docstring standards
  • Supports various output formats for easy integration with other tools

Cons

  • May produce false positives in some cases, requiring manual review
  • Limited to PEP 257 conventions by default, which may not suit all project styles
  • Can be overly strict for some developers, potentially slowing down development
  • Requires additional setup and maintenance in the development workflow

Code Examples

  1. Basic usage:
from pydocstyle import check
from pydocstyle.violations import Error

errors = list(check(['file.py']))
for error in errors:
    print(error)

This code checks a single file for docstring violations and prints any errors found.

  1. Checking multiple files:
import os
from pydocstyle import check

python_files = [f for f in os.listdir('.') if f.endswith('.py')]
for error in check(python_files):
    print(f"{error.filename}:{error.line} - {error.message}")

This example checks all Python files in the current directory and prints errors with filename and line number.

  1. Using specific error codes:
from pydocstyle import check
from pydocstyle.violations import Error

select = ['D100', 'D101', 'D102']  # Only check for these error codes
for error in check(['file.py'], select=select):
    print(f"Error {error.code}: {error.message}")

This code checks for specific error codes (missing module, class, and function docstrings) in a file.

Getting Started

To get started with pydocstyle:

  1. Install pydocstyle:

    pip install pydocstyle
    
  2. Run pydocstyle on a Python file:

    pydocstyle your_file.py
    
  3. To check an entire project, run:

    pydocstyle your_project_directory
    
  4. Create a configuration file (.pydocstyle) in your project root to customize rules:

    [pydocstyle]
    ignore = D100,D203,D405
    match = .*\.py
    

Competitor Comparisons

13,756

A formatter for Python files

Pros of yapf

  • Offers more comprehensive code formatting, including indentation, line breaks, and spacing
  • Highly configurable with style options to match different coding standards
  • Can be used as a command-line tool or integrated into various IDEs and editors

Cons of yapf

  • Focuses solely on code formatting, not docstring style or content
  • May require more setup and configuration to achieve desired formatting
  • Can sometimes produce unexpected or undesired formatting in complex code structures

Code comparison

pydocstyle (checks docstring style):

def example_function():
    """This is a docstring.

    It should follow PEP 257 conventions.
    """
    pass

yapf (formats code structure):

def example_function():
    some_long_variable_name = [
        'item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7'
    ]
    return some_long_variable_name

Summary

pydocstyle focuses specifically on docstring conventions, while yapf is a more general-purpose code formatter. pydocstyle is simpler to use for its specific purpose, but yapf offers broader formatting capabilities. The choice between them depends on whether you need docstring checking or overall code formatting.

38,772

The uncompromising Python code formatter

Pros of Black

  • Opinionated and deterministic formatting, reducing debates over code style
  • Faster execution time for large codebases
  • Integrates well with popular IDEs and text editors

Cons of Black

  • Less flexible than pydocstyle, with fewer configuration options
  • Focuses solely on code formatting, not docstring conventions
  • May require significant changes to existing codebases

Code Comparison

Black formatting example:

def long_function_name(
    var_one: int, var_two: str, var_three: float, var_four: bool
) -> bool:
    return var_four

pydocstyle focuses on docstring conventions:

def example_function(param1, param2):
    """
    This is a docstring that pydocstyle would check.

    Args:
        param1: Description of param1
        param2: Description of param2
    """
    pass

Black is a code formatter that enforces a consistent style across Python projects, while pydocstyle is a tool for checking compliance with Python docstring conventions. Black aims to eliminate discussions about code formatting, while pydocstyle helps maintain consistent and informative documentation. Black is more opinionated and less configurable, whereas pydocstyle offers more flexibility in adhering to different docstring styles.

3,428

flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code.

Pros of flake8

  • Comprehensive linting: Checks style, syntax, and potential errors
  • Extensible with plugins for additional checks
  • Configurable to match project-specific coding standards

Cons of flake8

  • Primarily focused on code style and syntax, less emphasis on docstring conventions
  • Can be overwhelming with numerous configuration options

Pros of pydocstyle

  • Specialized in checking docstring conventions
  • Supports various docstring styles (e.g., Google, NumPy, PEP 257)

Cons of pydocstyle

  • Limited to docstring checks, doesn't cover other code quality aspects
  • Fewer configuration options compared to flake8

Code comparison

flake8:

import sys

def example_function():
    print "Hello, World!"  # Syntax error (Python 3)
    unused_variable = 42   # Unused variable warning

pydocstyle:

def example_function():
    """This is a docstring.

    It doesn't follow any specific convention."""
    pass

flake8 would flag syntax errors and unused variables, while pydocstyle would focus on docstring format and content.

5,286

It's not just a linter that annoys you!

Pros of pylint

  • More comprehensive linting, covering a wider range of Python code quality issues
  • Highly configurable with many options to customize checks and behavior
  • Integrates well with various IDEs and development environments

Cons of pylint

  • Can be slower to run, especially on larger codebases
  • May produce more false positives, requiring fine-tuning of configuration
  • Steeper learning curve due to its extensive feature set

Code comparison

pydocstyle focuses specifically on docstring conventions:

def example_function():
    """This is a docstring."""
    pass

pylint covers a broader range of issues, including docstrings and more:

def example_function():
    """This is a docstring."""
    unused_variable = 10  # pylint will flag this
    return None  # pylint may suggest using 'return' alone

Summary

pydocstyle is a specialized tool for checking docstring conventions, while pylint is a more comprehensive linter that covers a wide range of Python code quality issues. pydocstyle is simpler and faster, focusing solely on docstrings, whereas pylint offers more extensive checks but may require more configuration and can be slower on larger projects. The choice between them depends on the specific needs of the project and the desired level of code quality enforcement.

30,822

An extremely fast Python linter and code formatter, written in Rust.

Pros of Ruff

  • Significantly faster performance due to Rust implementation
  • Broader scope, covering multiple linting and formatting tasks beyond docstring checks
  • Actively maintained with frequent updates and improvements

Cons of Ruff

  • Less specialized for docstring checking compared to Pydocstyle
  • May require additional configuration to focus solely on docstring-related issues
  • Newer project with potentially less established community support for docstring-specific queries

Code Comparison

Pydocstyle:

from pydocstyle import check
for error in check(['myfile.py']):
    print(error)

Ruff:

from ruff import check
results = check(["myfile.py"])
for result in results:
    print(result)

Both tools can be used to check Python files for style issues, including docstring-related problems. However, Ruff's implementation is more general-purpose and may require additional configuration to focus specifically on docstring checks.

A framework for managing and maintaining multi-language pre-commit hooks.

Pros of pre-commit

  • Supports multiple programming languages and tools, not limited to Python
  • Provides a framework for managing and maintaining pre-commit hooks
  • Allows for easy integration of various linters and formatters

Cons of pre-commit

  • Requires additional setup and configuration
  • May have a steeper learning curve for beginners
  • Not specifically focused on docstring checking

Code comparison

pre-commit configuration example:

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer

pydocstyle usage example:

from pydocstyle import check
from pydocstyle.violations import Error

errors = list(check(['file.py']))
for error in errors:
    print(error)

pre-commit is a versatile tool for managing pre-commit hooks across various languages and tools, while pydocstyle focuses specifically on checking Python docstrings. pre-commit offers more flexibility and broader application, but requires more setup. pydocstyle is simpler to use for its specific purpose but lacks the extensibility of pre-commit.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pydocstyle - docstring style checker

====================================== Deprecation Notice: Pydocstyle

.. IMPORTANT: Deprecation Notice :style: alert

.. image:: https://img.shields.io/badge/deprecated-red :target: https://github.com/PyCQA/pydocstyle :alt: Deprecated

The Pydocstyle project is officially deprecated, and it is no longer actively maintained.

Ruff: A Modern Alternative

  • GitHub Repository: ruff <https://github.com/astral-sh/ruff>_

Ruff offers full parity with pydocstyle along with advanced features, better support for the latest Python versions, and ongoing development to ensure a top-notch linting experience. We highly recommend pydocstyle users to switch over to ruff for a seamless transition.

A Heartfelt Thank You

We want to express our heartfelt gratitude to the pydocstyle community, maintainers, and contributors for their support and dedication over the years. Your contributions have been invaluable, and we appreciate the time and effort you've invested in making pydocstyle a valuable tool for the Python community.

Thank you for your support of pydocstyle in the past.


.. image:: https://github.com/PyCQA/pydocstyle/workflows/Run%20tests/badge.svg :target: https://github.com/PyCQA/pydocstyle/actions?query=workflow%3A%22Run+tests%22+branch%3Amaster

.. image:: https://readthedocs.org/projects/pydocstyle/badge/?version=latest :target: https://readthedocs.org/projects/pydocstyle/?badge=latest :alt: Documentation Status

.. image:: https://img.shields.io/pypi/pyversions/pydocstyle.svg :target: https://pypi.org/project/pydocstyle

.. image:: https://pepy.tech/badge/pydocstyle :target: https://pepy.tech/project/pydocstyle

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg :target: https://github.com/psf/black

.. image:: https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336 :target: https://pycqa.github.io/isort/

.. image:: https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod :target: https://gitpod.io/#https://github.com/PyCQA/pydocstyle :alt: Gitpod ready-to-code

pydocstyle is a static analysis tool for checking compliance with Python docstring conventions.

pydocstyle supports most of PEP 257 <http://www.python.org/dev/peps/pep-0257/>_ out of the box, but it should not be considered a reference implementation.

pydocstyle supports Python 3.6+.

Quick Start

Install ^^^^^^^

.. code::

pip install pydocstyle

Run ^^^

.. code::

$ pydocstyle test.py
test.py:18 in private nested class `meta`:
        D101: Docstring missing
test.py:27 in public function `get_user`:
    D300: Use """triple double quotes""" (found '''-quotes)
test:75 in public function `init_database`:
    D201: No blank lines allowed before function docstring (found 1)
...

Develop ^^^^^^^

You can use Gitpod to run pre-configured dev environment in the cloud right from your browser -

.. image:: https://gitpod.io/button/open-in-gitpod.svg :target: https://gitpod.io/#https://github.com/PyCQA/pydocstyle :alt: Open in Gitpod

Before submitting a PR make sure that you run make all.

Links

  • Read the full documentation here <https://pydocstyle.org/en/stable/>_.

  • Fork pydocstyle on GitHub <https://github.com/PyCQA/pydocstyle>_.

  • PyPI project page <https://pypi.python.org/pypi/pydocstyle>_.