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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy