Skip to content

Commit

Permalink
OptionalChainer -> NullCoalescer
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed May 30, 2022
1 parent cbc46d3 commit 9c7e274
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 12 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions docs/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions pyccolo/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -11,7 +11,7 @@
"CoverageTracer",
"FutureTracer",
"LazyImportTracer",
"NullCoalescer",
"OptionalChainer",
"Quasiquoter",
"QuickLambdaTracer",
]
1 change: 1 addition & 0 deletions pyccolo/examples/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
)


class NullCoalescer(pyc.BaseTracer):
class OptionalChainer(pyc.BaseTracer):
class DotIsAlwaysNone:
def __getattr__(self, _item):
return None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.']
Expand Down
4 changes: 2 additions & 2 deletions test/test_script_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ 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()
)
)

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()
)
)
4 changes: 2 additions & 2 deletions test/test_syntax_augmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
File renamed without changes.

0 comments on commit 9c7e274

Please sign in to comment.