Skip to content

Commit 2ebbf3b

Browse files
authored
Compile attrs instances without cmp kwarg if version >= 19.2.0 (#448)
* Compile attrs instances without cmp kwarg if version >= 19.2.0 * Fix Circle config and Makefile * Specify coverage and safety in Tox envlist * Not that
1 parent 7b2260f commit 2ebbf3b

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

.circleci/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ jobs:
1919
environment:
2020
TOX_NUM_CORES: 2
2121
TOX_SHOW_OUTPUT: "True"
22+
TOX_SKIP_ENV: pypy3
2223
command: |
23-
tox -p $TOX_NUM_CORES -e py36,py37,py38,coverage,mypy,format,lint,safety
24+
tox -p $TOX_NUM_CORES
2425
- save_cache:
2526
key: deps9-{{ .Branch }}-{{ checksum "tox.ini" }}-{{ checksum "Pipfile.lock" }}
2627
paths:

Makefile

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@ repl:
2727
@BASILISP_USE_DEV_LOGGER=true pipenv run basilisp repl
2828

2929

30-
# Run PyPy tests inside a Docker container for the moment since
31-
# Pyenv on MacOS still doesn't have PyPy 3.6-7.0.0.
32-
.PHONY: test-pypy
33-
test-pypy:
34-
@docker run \
35-
--mount src=`pwd`,target=/usr/src/app,type=bind \
36-
--workdir /usr/src/app \
37-
pypy:3.6-7.0-slim-jessie \
38-
/bin/sh -c 'pip install tox && tox -e pypy3'
39-
40-
4130
.PHONY: pypy-shell
4231
pypy-shell:
4332
@docker run -it \
@@ -49,4 +38,5 @@ pypy-shell:
4938

5039
.PHONY: test
5140
test:
52-
@pipenv run tox -p 4
41+
@rm -f .coverage*
42+
@TOX_SKIP_ENV='pypy3|safety|coverage' pipenv run tox -p 4

src/basilisp/lang/compiler/generator.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ def __deftype_member_to_py_ast(
866866
return handle_deftype_member(ctx, node)
867867

868868

869+
_ATTR_CMP_OFF = getattr(attr, "__version_info__", (0,)) >= (19, 2)
870+
_ATTR_CMP_KWARGS = (
871+
[
872+
ast.keyword(arg="eq", value=ast.Constant(False)),
873+
ast.keyword(arg="order", value=ast.Constant(False)),
874+
]
875+
if _ATTR_CMP_OFF
876+
else [ast.keyword(arg="cmp", value=ast.Constant(False))]
877+
)
878+
879+
869880
@_with_ast_loc
870881
def _deftype_to_py_ast( # pylint: disable=too-many-branches
871882
ctx: GeneratorContext, node: DefType
@@ -886,8 +897,8 @@ def _deftype_to_py_ast( # pylint: disable=too-many-branches
886897
decorator = ast.Call(
887898
func=_ATTR_CLASS_DECORATOR_NAME,
888899
args=[],
889-
keywords=[
890-
ast.keyword(arg="cmp", value=ast.Constant(False)),
900+
keywords=_ATTR_CMP_KWARGS
901+
+ [
891902
ast.keyword(arg="frozen", value=ast.Constant(node.is_frozen)),
892903
ast.keyword(arg="slots", value=ast.Constant(True)),
893904
],
@@ -1593,7 +1604,7 @@ def _loop_to_py_ast(ctx: GeneratorContext, node: Loop) -> GeneratedPyAST:
15931604
):
15941605
loop_body_ast: List[ast.AST] = []
15951606
body_ast = _synthetic_do_to_py_ast(ctx, node.body)
1596-
loop_body_ast.extend(body_ast.dependencies)
1607+
loop_body_ast.extend(map(statementize, body_ast.dependencies))
15971608
loop_body_ast.append(
15981609
ast.Assign(
15991610
targets=[ast.Name(id=loop_result_name, ctx=ast.Store())],

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py36,py37,py38,mypy,format,lint
2+
envlist = py36,py37,py38,pypy3,coverage,mypy,format,lint,safety
33

44
[testenv]
55
parallel_show_output = {env:TOX_SHOW_OUTPUT:false}

0 commit comments

Comments
 (0)