From 9c7e2745b46cbac5d9a5f159133f24cea0c63721 Mon Sep 17 00:00:00 2001 From: Stephen Macke Date: Mon, 30 May 2022 10:23:19 -0700 Subject: [PATCH] OptionalChainer -> NullCoalescer --- README.md | 8 ++++---- docs/HISTORY.rst | 4 ++++ pyccolo/examples/__init__.py | 4 ++-- pyccolo/examples/coverage.py | 1 + .../examples/{null_coalesce.py => optional_chaining.py} | 2 +- pyproject.toml | 2 +- test/test_script_entrypoint.py | 4 ++-- test/test_syntax_augmentation.py | 4 ++-- test/{uses_null_coalesce.py => uses_optional_chaining.py} | 0 9 files changed, 17 insertions(+), 12 deletions(-) rename pyccolo/examples/{null_coalesce.py => optional_chaining.py} (95%) rename test/{uses_null_coalesce.py => uses_optional_chaining.py} (100%) diff --git a/README.md b/README.md index 4d99bca..4070dd5 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Pyccolo can be used (and has been used) to implement various kinds of dynamic an tools and other instrumentation: - Code coverage (see [pyccolo/examples/coverage.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/coverage.py)) - Syntactic macros such as quasiquotes (like [MacroPy's](https://macropy3.readthedocs.io/en/latest/reference.html#quasiquote)) or quick lambdas; see [pyccolo/examples/quasiquote.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/quasiquote.py) and [pyccolo/examples/quick_lambda.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/quick_lambda.py) -- Syntax-augmented Python (3.8 and up, see [pyccolo/examples/null_coalesce.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/null_coalesce.py)) +- Syntax-augmented Python (3.8 and up, see [pyccolo/examples/optional_chaining.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/optional_chaining.py)) - Dynamic dataflow analysis performed by [nbsafety](https://github.com/nbsafety-project/nbsafety) - Tools to perform (most) imports lazily (see [pyccolo/examples/lazy_imports.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/lazy_imports.py)) - Tools to uncover [semantic memory leaks](http://ithare.com/java-vs-c-trading-ub-for-semantic-memory-leaks-same-problem-different-punishment-for-failure/) @@ -162,7 +162,7 @@ later when instrumentation is not desired). ## Command Line Interface You can execute arbitrary scripts with instrumentation enabled with the `pyc` command line tool. -For example, to use the `NullCoalescer` tracer defined in [pyccolo/examples/null_coalesce.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/null_coalesce.py), +For example, to use the `OptionalChainer` tracer defined in [pyccolo/examples/optional_chaining.py](https://github.com/smacke/pyccolo/blob/master/pyccolo/examples/optional_chaining.py), you can call `pyc` as follows, given some example script `bar.py`: ```python @@ -173,13 +173,13 @@ print(bar?.foo) ``` ```bash -> pyc bar.py -t pyccolo.examples.NullCoalescer +> pyc bar.py -t pyccolo.examples.OptionalChainer ``` You can also run `bar` as a module (indeed, `pyc` performs this internally when provided a file): ```bash -> pyc -m bar -t pyccolo.examples.NullCoalescer +> pyc -m bar -t pyccolo.examples.OptionalChainer ``` Note that you can specify multiple tracer classes after the `-t` argument; diff --git a/docs/HISTORY.rst b/docs/HISTORY.rst index 546aaf7..e1acb79 100644 --- a/docs/HISTORY.rst +++ b/docs/HISTORY.rst @@ -1,6 +1,10 @@ History ======= +0.0.27 (2022-05-30) +------------------ +* OptionalChainer -> NullCoalescer; + 0.0.26 (2022-05-21) ------------------ * Get rid of phantom dependency on pytest; diff --git a/pyccolo/examples/__init__.py b/pyccolo/examples/__init__.py index 0afba6b..cc43d55 100644 --- a/pyccolo/examples/__init__.py +++ b/pyccolo/examples/__init__.py @@ -2,7 +2,7 @@ from .coverage import CoverageTracer from .future_tracer import FutureTracer from .lazy_imports import LazyImportTracer -from .null_coalesce import NullCoalescer +from .optional_chaining import OptionalChainer from .quasiquote import Quasiquoter from .quick_lambda import QuickLambdaTracer @@ -11,7 +11,7 @@ "CoverageTracer", "FutureTracer", "LazyImportTracer", - "NullCoalescer", + "OptionalChainer", "Quasiquoter", "QuickLambdaTracer", ] diff --git a/pyccolo/examples/coverage.py b/pyccolo/examples/coverage.py index cf6c024..85deb02 100644 --- a/pyccolo/examples/coverage.py +++ b/pyccolo/examples/coverage.py @@ -120,6 +120,7 @@ def remove_pyccolo_modules(): if __name__ == "__main__": import pytest + sys.path.insert(0, ".") # now clear pyccolo modules so that they get reimported, and instrumented # can be omitted for non-pyccolo projects diff --git a/pyccolo/examples/null_coalesce.py b/pyccolo/examples/optional_chaining.py similarity index 95% rename from pyccolo/examples/null_coalesce.py rename to pyccolo/examples/optional_chaining.py index 47bca86..e04ed75 100644 --- a/pyccolo/examples/null_coalesce.py +++ b/pyccolo/examples/optional_chaining.py @@ -12,7 +12,7 @@ ) -class NullCoalescer(pyc.BaseTracer): +class OptionalChainer(pyc.BaseTracer): class DotIsAlwaysNone: def __getattr__(self, _item): return None diff --git a/pyproject.toml b/pyproject.toml index 752bb11..40b642e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ enabled = true [tool.black] line-length = 88 target-version = ['py39'] -extend-exclude = '(^/versioneer|_version|.*uses_null_coalesce)\.py' +extend-exclude = '(^/versioneer|_version|.*uses_optional_chaining)\.py' [tool.pytest.ini_options] markers = ['integration: mark a test as an integration test.'] diff --git a/test/test_script_entrypoint.py b/test/test_script_entrypoint.py index 746391e..f2f62ab 100644 --- a/test/test_script_entrypoint.py +++ b/test/test_script_entrypoint.py @@ -9,7 +9,7 @@ def test_entrypoint_with_script(): # just make sure it doesn't raise run( make_parser().parse_args( - "./test/uses_null_coalesce.py -t pyccolo.examples.NullCoalescer".split() + "./test/uses_optional_chaining.py -t pyccolo.examples.OptionalChainer".split() ) ) @@ -17,6 +17,6 @@ def test_entrypoint_with_module(): # just make sure it doesn't raise run( make_parser().parse_args( - "-m test.uses_null_coalesce -t pyccolo.examples.NullCoalescer".split() + "-m test.uses_optional_chaining -t pyccolo.examples.OptionalChainer".split() ) ) diff --git a/test/test_syntax_augmentation.py b/test/test_syntax_augmentation.py index e916aae..1089467 100644 --- a/test/test_syntax_augmentation.py +++ b/test/test_syntax_augmentation.py @@ -35,9 +35,9 @@ def handle_add(self, ret, node, *_, **__): ) def test_coalescing_dot(): - from pyccolo.examples import NullCoalescer + from pyccolo.examples import OptionalChainer - NullCoalescer.instance().exec( + OptionalChainer.instance().exec( """ class Foo: def __init__(self, x): diff --git a/test/uses_null_coalesce.py b/test/uses_optional_chaining.py similarity index 100% rename from test/uses_null_coalesce.py rename to test/uses_optional_chaining.py