alexmojaki / pure_eval

Safely evaluate AST nodes without side effects
MIT License
42 stars 16 forks source link

add pep-561 marker file #8

Closed hoefling closed 2 years ago

hoefling commented 3 years ago

This PR adds PEP 561 support for pure_eval. The rationale for this PR is that with the current 0.2.1 release, the type checks with mypy fail because pure_eval doesn't report having any type hints. A simple example to demonstrate:

import inspect
from pure_eval import Evaluator

evaluator = Evaluator.from_frame(inspect.currentframe())

Installing pure_eval from PyPI and analyzing the snippet yields unavailable type hints:

$ pip install pure-eval==0.2.1 --no-cache-dir
...
$ mypy spam.py 
spam.py:2: error: Skipping analyzing "pure_eval": found module but no type hints or library stubs
spam.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

Adding the py.typed marker manually (or installing from this PR!) now yields the expected type checking error:

$ touch $(python -c "import pure_eval; print(pure_eval.__path__[0])")/py.typed
$ mypy spam.py 
spam.py:4: error: Argument 1 to "from_frame" of "Evaluator" has incompatible type "Optional[FrameType]"; expected "FrameType"
Found 1 error in 1 file (checked 1 source file)
alexmojaki commented 2 years ago

Sorry for the delay. I don't really know what this PR means, but thanks anyway!