Skip to content

Commit 678425a

Browse files
authored
Refactor primary interfaces so they are easier to use in deftype (#370)
Refactor all of the primary data structure interfaces so they are easier to use for deftype* forms. Precursor to #369 In particular, reduce the use of concrete types in favor of interface types, particularly in Basilisp code.
1 parent 7713c0c commit 678425a

39 files changed

+1053
-700
lines changed

.prospector.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ test-warnings: true
55
doc-warnings: false
66

77
ignore-paths:
8+
- .cache
9+
- .mypy_cache
10+
- .pytest_cache
11+
- .tox
12+
- build
13+
- dist
814
- tests
915

1016
pep8:

mypy.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[mypy]
2+
check_untyped_defs = True
3+
warn_unused_ignores = True
4+
5+
[mypy-atomos.*]
6+
ignore_missing_imports = True
7+
8+
[mypy-astor.*]
9+
ignore_missing_imports = True
10+
11+
[mypy-functional.*]
12+
ignore_missing_imports = True
13+
14+
[mypy-pytest.*]
15+
ignore_missing_imports = True

src/basilisp/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ def repl(
160160
if result is eof: # pragma: no cover
161161
continue
162162
print(runtime.lrepr(result))
163-
repl_module.mark_repl_result(result)
163+
repl_module.mark_repl_result(result) # type: ignore
164164
except reader.SyntaxError as e:
165165
traceback.print_exception(reader.SyntaxError, e, e.__traceback__)
166-
repl_module.mark_exception(e)
166+
repl_module.mark_exception(e) # type: ignore
167167
continue
168168
except compiler.CompilerException as e:
169169
traceback.print_exception(compiler.CompilerException, e, e.__traceback__)
170-
repl_module.mark_exception(e)
170+
repl_module.mark_exception(e) # type: ignore
171171
continue
172172
except Exception as e:
173173
traceback.print_exception(Exception, e, e.__traceback__)
174-
repl_module.mark_exception(e)
174+
repl_module.mark_exception(e) # type: ignore
175175
continue
176176

177177

src/basilisp/core/__init__.lpy

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,35 +135,35 @@
135135
:arglists '([o])}
136136
list?
137137
(fn list? [o]
138-
(instance? basilisp.lang.list/List o)))
138+
(instance? basilisp.lang.interfaces/IPersistentList o)))
139139

140140
(def
141141
^{:doc "Return true if o is a map."
142142
:arglists '([o])}
143143
map?
144144
(fn map? [o]
145-
(instance? basilisp.lang.map/Map o)))
145+
(instance? basilisp.lang.interfaces/IPersistentMap o)))
146146

147147
(def
148148
^{:doc "Return true if o is a set."
149149
:arglists '([o])}
150150
set?
151151
(fn set? [o]
152-
(instance? basilisp.lang.set/Set o)))
152+
(instance? basilisp.lang.interfaces/IPersistentSet o)))
153153

154154
(def
155155
^{:doc "Return true if o is a vector."
156156
:arglists '([o])}
157157
vector?
158158
(fn vector? [o]
159-
(instance? basilisp.lang.vector/Vector o)))
159+
(instance? basilisp.lang.interfaces/IPersistentVector o)))
160160

161161
(def
162162
^{:doc "Return true if o implements Seq."
163163
:arglists '([o])}
164164
seq?
165165
(fn seq? [o]
166-
(instance? basilisp.lang.seq/Seq o)))
166+
(instance? basilisp.lang.interfaces/ISeq o)))
167167

168168
(def ^{:doc "Coerce the argument o to a Seq. If o is nil, return nil."
169169
:arglists '([o])}

src/basilisp/importer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import sys
88
import types
99
from importlib.abc import MetaPathFinder, SourceLoader
10-
from typing import Optional, List, Dict
10+
from typing import List, Mapping, MutableMapping, Optional
1111

1212
import basilisp.lang.compiler as compiler
1313
import basilisp.lang.reader as reader
@@ -92,7 +92,7 @@ class BasilispImporter(MetaPathFinder, SourceLoader):
9292
Python."""
9393

9494
def __init__(self):
95-
self._cache = {}
95+
self._cache: MutableMapping[str, dict] = {}
9696

9797
def find_spec(
9898
self,
@@ -175,8 +175,8 @@ def create_module(self, spec: importlib.machinery.ModuleSpec):
175175
def _exec_cached_module(
176176
self,
177177
fullname: str,
178-
loader_state: Dict[str, str],
179-
path_stats: Dict[str, int],
178+
loader_state: Mapping[str, str],
179+
path_stats: Mapping[str, int],
180180
module: types.ModuleType,
181181
):
182182
"""Load and execute a cached Basilisp module."""
@@ -203,8 +203,8 @@ def _exec_cached_module(
203203
def _exec_module(
204204
self,
205205
fullname: str,
206-
loader_state: Dict[str, str],
207-
path_stats: Dict[str, int],
206+
loader_state: Mapping[str, str],
207+
path_stats: Mapping[str, int],
208208
module: types.ModuleType,
209209
):
210210
"""Load and execute a non-cached Basilisp module."""

src/basilisp/lang/associative.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/basilisp/lang/atom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
from typing import Generic, TypeVar, Callable
1+
from typing import Callable, Generic, TypeVar
22

33
import atomos.atom
44

5-
from basilisp.lang.deref import Deref
5+
from basilisp.lang.interfaces import IDeref
66

77
T = TypeVar("T")
88

99

10-
class Atom(Deref, Generic[T]):
10+
class Atom(IDeref[T], Generic[T]):
1111
__slots__ = ("_atom",)
1212

1313
def __init__(self, state: T) -> None:
14-
self._atom = atomos.atom.Atom(state)
14+
self._atom = atomos.atom.Atom(state) # pylint: disable=assigning-non-slot
1515

1616
def compare_and_set(self, old, new):
1717
return self._atom.compare_and_set(old, new)

src/basilisp/lang/collection.py

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/basilisp/lang/compiler/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import itertools
33
import os
44
import types
5-
from typing import Any, Callable, Dict, Iterable, List, Optional
5+
from typing import Any, Callable, Iterable, List, Mapping, Optional
66

77
from astor import code_gen as codegen
88

@@ -44,7 +44,7 @@ def to_py_str(t: ast.AST) -> str:
4444
class CompilerContext:
4545
__slots__ = ("_filename", "_gctx", "_pctx", "_optimizer")
4646

47-
def __init__(self, filename: str, opts: Optional[Dict[str, bool]] = None):
47+
def __init__(self, filename: str, opts: Optional[Mapping[str, bool]] = None):
4848
self._filename = filename
4949
self._gctx = GeneratorContext(filename=filename, opts=opts)
5050
self._pctx = ParserContext(filename=filename, opts=opts)

src/basilisp/lang/compiler/exception.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import basilisp.lang.keyword as kw
88
from basilisp.lang.compiler.nodes import Node
9-
from basilisp.lang.seq import Seq
9+
from basilisp.lang.interfaces import ISeq
1010
from basilisp.lang.typing import LispForm
1111

1212

@@ -21,6 +21,6 @@ class CompilerPhase(Enum):
2121
class CompilerException(Exception):
2222
msg: str
2323
phase: CompilerPhase
24-
form: Union[LispForm, None, Seq] = None
24+
form: Union[LispForm, None, ISeq] = None
2525
lisp_ast: Optional[Node] = None
2626
py_ast: Optional[ast.AST] = None

0 commit comments

Comments
 (0)