Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The enable_packrat type annotation prevents passing None for cache_size_limit #498

Closed
mikeurbach opened this issue Jul 20, 2023 · 3 comments · Fixed by #499
Closed

The enable_packrat type annotation prevents passing None for cache_size_limit #498

mikeurbach opened this issue Jul 20, 2023 · 3 comments · Fixed by #499

Comments

@mikeurbach
Copy link
Contributor

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.

@ptmcg
Copy link
Member

ptmcg commented Jul 20, 2023

Thanks for spotting this - I'm happy to see that my attempts at type hints are finding an audience.

@ptmcg
Copy link
Member

ptmcg commented Jul 30, 2023

Released today in pyparsing 3.1.1

@mikeurbach
Copy link
Contributor Author

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants