Skip to content

The enable_packrat type annotation prevents passing None for cache_size_limit #498

@mikeurbach

Description

@mikeurbach

The method enable_packrat has a type annotation for cache_size_limit: int, as well as a default value of 128:

def enable_packrat(cache_size_limit: int = 128, *, force: bool = False) -> None:

However, the method's docstring and implementation indicate that passing None will lead to an unbounded cache:

pyparsing/pyparsing/core.py

Lines 1119 to 1120 in d5aafc3

if cache_size_limit is None:
ParserElement.packrat_cache = _UnboundedCache()

In a downstream project, we'd like to be able to pass None, and also use a typechecker to check our project. Currently, this doesn't seems possible. For example, mypy will say:

pydevicetree/source/grammar.py:23: error: Argument 1 to "enable_packrat" of "ParserElement" has incompatible type "int | None"; expected "int"  [arg-type]

It seems like a simple update to the type annotation of enable_packrat. I'm happy to send a PR for that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions