Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/basilisp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import sys
import textwrap
import types
from collections.abc import Sequence
from collections.abc import Callable, Sequence
from pathlib import Path
from typing import Any, Callable, Optional, Union
from typing import Any, Union

from basilisp import main as basilisp
from basilisp.lang import compiler as compiler
Expand Down Expand Up @@ -97,7 +97,7 @@ def prepend_once(path: str) -> None:
prepend_once(unsafe_path)


def _to_bool(v: Optional[str]) -> Optional[bool]:
def _to_bool(v: str | None) -> bool | None:
"""Coerce a string argument to a boolean value, if possible."""
if v is None:
return v
Expand Down Expand Up @@ -389,8 +389,8 @@ def _add_runtime_arg_group(parser: argparse.ArgumentParser) -> None:
def _subcommand(
subcommand: str,
*,
help: Optional[str] = None, # pylint: disable=redefined-builtin
description: Optional[str] = None,
help: str | None = None, # pylint: disable=redefined-builtin
description: str | None = None,
handler: Handler,
allows_extra: bool = False,
) -> Callable[
Expand Down Expand Up @@ -820,7 +820,7 @@ def run_script():
os.execvp("basilisp", args) # nosec B606, B607


def invoke_cli(args: Optional[Sequence[str]] = None) -> None:
def invoke_cli(args: Sequence[str] | None = None) -> None:
"""Entrypoint to run the Basilisp CLI."""
parser = argparse.ArgumentParser(
description="Basilisp is a Lisp dialect inspired by Clojure targeting Python 3."
Expand Down
14 changes: 7 additions & 7 deletions src/basilisp/contrib/pytest/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import os
import sys
import traceback
from collections.abc import Iterable, Iterator
from collections.abc import Callable, Iterable, Iterator
from pathlib import Path
from types import GeneratorType
from typing import Callable, Optional
from typing import Optional

import pytest

Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, fixtures: Iterable[FixtureFunction]):
self._teardowns: Iterable[FixtureTeardown] = ()

@staticmethod
def _run_fixture(fixture: FixtureFunction) -> Optional[Iterator[None]]:
def _run_fixture(fixture: FixtureFunction) -> Iterator[None] | None:
"""Run a fixture function. If the fixture is a generator function, return the
generator/coroutine. Otherwise, simply return the value from the function, if
one."""
Expand Down Expand Up @@ -199,7 +199,7 @@ class BasilispFile(pytest.File):

def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
self._fixture_manager: Optional[FixtureManager] = None
self._fixture_manager: FixtureManager | None = None

@staticmethod
def _collected_fixtures(
Expand Down Expand Up @@ -248,7 +248,7 @@ def _import_module(self) -> runtime.BasilispModule:
modnames = _get_fully_qualified_module_names(self.path)
assert modnames, "Must have at least one module name"

exc: Optional[ModuleNotFoundError] = None
exc: ModuleNotFoundError | None = None
for modname in modnames:
try:
module = importlib.import_module(modname)
Expand Down Expand Up @@ -360,7 +360,7 @@ def runtest(self):
If any tests fail, raise an ExceptionInfo exception with the test failures.
PyTest will invoke self.repr_failure to display the failures to the user."""
results: lmap.PersistentMap = self._run_test()
failures: Optional[vec.PersistentVector] = results.val_at(_FAILURES_KW)
failures: vec.PersistentVector | None = results.val_at(_FAILURES_KW)
if runtime.to_seq(failures):
raise TestFailuresInfo("Test failures", lmap.map(results))

Expand Down Expand Up @@ -391,7 +391,7 @@ def repr_failure(self, excinfo, style=None):
def reportinfo(self):
return self.fspath, 0, self.name

def _error_msg(self, exc: Exception, line: Optional[int] = None) -> str:
def _error_msg(self, exc: Exception, line: int | None = None) -> str:
line_msg = Maybe(line).map(lambda l: f":{l}").or_else_get("")
messages = [f"ERROR in ({self.name}) ({self._filename}{line_msg})", "\n\n"]
messages.extend(traceback.format_exception(Exception, exc, exc.__traceback__))
Expand Down
14 changes: 7 additions & 7 deletions src/basilisp/contrib/sphinx/autodoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sys
import types
from typing import Any, Optional, cast
from typing import Any, cast

from sphinx.ext.autodoc import (
ClassDocumenter,
Expand Down Expand Up @@ -51,7 +51,7 @@
_METHODS_KW = kw.keyword("methods")


def _get_doc(reference: IReference) -> Optional[list[list[str]]]:
def _get_doc(reference: IReference) -> list[list[str]] | None:
"""Return the docstring of an IReference type (e.g. Namespace or Var)."""
docstring = reference.meta and reference.meta.val_at(_DOC_KW)
if docstring is None:
Expand Down Expand Up @@ -79,7 +79,7 @@ class NamespaceDocumenter(Documenter):
"deprecated": bool_option,
}

object: Optional[runtime.Namespace]
object: runtime.Namespace | None

@classmethod
def can_document_member(
Expand Down Expand Up @@ -122,7 +122,7 @@ def import_object(self, raiseerror: bool = False) -> bool:
self.module = ns.module
return True

def get_doc(self) -> Optional[list[list[str]]]:
def get_doc(self) -> list[list[str]] | None:
assert self.object is not None
return _get_doc(self.object)

Expand Down Expand Up @@ -155,7 +155,7 @@ def filter_members(
continue
if val.meta is not None:
# Ignore undocumented members unless undoc_members is set
docstring: Optional[str] = val.meta.val_at(_DOC_KW)
docstring: str | None = val.meta.val_at(_DOC_KW)
if docstring is None and not self.options.undoc_members:
continue
# Private members will be excluded unless they are requested
Expand Down Expand Up @@ -215,7 +215,7 @@ class VarDocumenter(Documenter):
"deprecated": bool_option,
}

object: Optional[runtime.Var]
object: runtime.Var | None

@classmethod
def can_document_member(
Expand Down Expand Up @@ -292,7 +292,7 @@ def add_directive_header(self, sig: str) -> None:
if self.object.meta.val_at(_DEPRECATED_KW):
self.add_line(" :deprecated:", sourcename)

def get_doc(self) -> Optional[list[list[str]]]:
def get_doc(self) -> list[list[str]] | None:
assert self.object is not None
return _get_doc(self.object)

Expand Down
8 changes: 4 additions & 4 deletions src/basilisp/contrib/sphinx/domain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from collections import defaultdict
from collections.abc import Iterable
from typing import Any, NamedTuple, Optional, Union, cast
from typing import Any, NamedTuple, cast

from docutils import nodes
from docutils.nodes import Element, Node
Expand Down Expand Up @@ -316,7 +316,7 @@ class BasilispNamespaceIndex(Index):
shortname = "namespaces"

def generate( # pylint: disable=too-many-locals
self, docnames: Optional[Iterable[str]] = None
self, docnames: Iterable[str] | None = None
) -> tuple[list[tuple[str, list[IndexEntry]]], bool]:
content: dict[str, list[IndexEntry]] = defaultdict(list)

Expand Down Expand Up @@ -548,10 +548,10 @@ def resolve_xref( # pylint: disable=too-many-arguments
target: str,
node: pending_xref,
contnode: Element,
) -> Optional[Element]:
) -> Element | None:
nsname = node.get("lpy:namespace")

maybe_obj: Union[FormEntry, NamespaceEntry, VarEntry, None]
maybe_obj: FormEntry | NamespaceEntry | VarEntry | None
reftype = node.get("reftype")
if reftype == "ns":
maybe_obj = self.namespaces.get(target)
Expand Down
10 changes: 5 additions & 5 deletions src/basilisp/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from functools import lru_cache
from importlib.abc import MetaPathFinder, SourceLoader
from importlib.machinery import ModuleSpec
from typing import Any, Optional, cast
from typing import Any, cast

from typing_extensions import TypedDict

Expand Down Expand Up @@ -144,9 +144,9 @@ def __init__(self):
def find_spec(
self,
fullname: str,
path: Optional[Sequence[str]],
target: Optional[types.ModuleType] = None,
) -> Optional[ModuleSpec]:
path: Sequence[str] | None,
target: types.ModuleType | None = None,
) -> ModuleSpec | None:
"""Find the ModuleSpec for the specified Basilisp module.

Returns None if the module is not a Basilisp module to allow import processing to continue.
Expand Down Expand Up @@ -234,7 +234,7 @@ def get_filename(self, fullname: str) -> str:
assert spec is not None, "spec must be defined here"
return spec.loader_state["filename"]

def get_code(self, fullname: str) -> Optional[types.CodeType]:
def get_code(self, fullname: str) -> types.CodeType | None:
"""Return code to load a Basilisp module.

This function is part of the ABC for `importlib.abc.ExecutionLoader` which is
Expand Down
11 changes: 6 additions & 5 deletions src/basilisp/lang/atom.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import threading
from typing import Callable, Generic, Optional, TypeVar
from collections.abc import Callable
from typing import Concatenate, Generic, TypeVar

from typing_extensions import Concatenate, ParamSpec
from typing_extensions import ParamSpec

from basilisp.lang import map as lmap
from basilisp.lang.interfaces import IPersistentMap, RefValidator
Expand All @@ -17,10 +18,10 @@ class Atom(RefBase[T], Generic[T]):
def __init__(
self,
state: T,
meta: Optional[IPersistentMap] = None,
validator: Optional[RefValidator] = None,
meta: IPersistentMap | None = None,
validator: RefValidator | None = None,
) -> None:
self._meta: Optional[IPersistentMap] = meta
self._meta: IPersistentMap | None = meta
self._state = state
self._lock = threading.RLock()
self._watches = lmap.EMPTY
Expand Down
36 changes: 18 additions & 18 deletions src/basilisp/lang/compiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import os
import types
from ast import unparse
from collections.abc import Iterable
from collections.abc import Callable, Iterable
from pathlib import Path
from typing import Any, Callable, Optional
from typing import Any

from basilisp.lang import list as llist
from basilisp.lang import map as lmap
Expand Down Expand Up @@ -60,7 +60,7 @@ def to_py_str(t: ast.AST) -> str:
class CompilerContext:
__slots__ = ("_filename", "_actx", "_gctx", "_optimizer")

def __init__(self, filename: str, opts: Optional[CompilerOpts] = None):
def __init__(self, filename: str, opts: CompilerOpts | None = None):
self._filename = filename
self._actx = AnalyzerContext(filename=filename, opts=opts)
self._gctx = GeneratorContext(filename=filename, opts=opts)
Expand All @@ -84,15 +84,15 @@ def py_ast_optimizer(self) -> PythonASTOptimizer:


def compiler_opts( # pylint: disable=too-many-arguments
generate_auto_inlines: Optional[bool] = None,
inline_functions: Optional[bool] = None,
warn_on_arity_mismatch: Optional[bool] = None,
warn_on_shadowed_name: Optional[bool] = None,
warn_on_shadowed_var: Optional[bool] = None,
warn_on_unused_names: Optional[bool] = None,
warn_on_non_dynamic_set: Optional[bool] = None,
use_var_indirection: Optional[bool] = None,
warn_on_var_indirection: Optional[bool] = None,
generate_auto_inlines: bool | None = None,
inline_functions: bool | None = None,
warn_on_arity_mismatch: bool | None = None,
warn_on_shadowed_name: bool | None = None,
warn_on_shadowed_var: bool | None = None,
warn_on_unused_names: bool | None = None,
warn_on_non_dynamic_set: bool | None = None,
use_var_indirection: bool | None = None,
warn_on_var_indirection: bool | None = None,
) -> CompilerOpts:
"""Return a map of compiler options with defaults applied."""
return lmap.map(
Expand Down Expand Up @@ -148,7 +148,7 @@ def compile_and_exec_form(
ctx: CompilerContext,
ns: runtime.Namespace,
wrapped_fn_name: str = _DEFAULT_FN,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> Any:
"""Compile and execute the given form. This function will be most useful
for the REPL and testing purposes. Returns the result of the executed expression.
Expand Down Expand Up @@ -204,7 +204,7 @@ def _incremental_compile_module(
py_ast: GeneratedPyAST,
module: BasilispModule,
source_filename: str,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> None:
"""Incrementally compile a stream of AST nodes in module mod.

Expand Down Expand Up @@ -232,7 +232,7 @@ def _bootstrap_module(
gctx: GeneratorContext,
optimizer: PythonASTOptimizer,
module: BasilispModule,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> None:
"""Bootstrap a new module with imports and other boilerplate."""
_incremental_compile_module(
Expand All @@ -249,7 +249,7 @@ def compile_module(
forms: Iterable[ReaderForm],
ctx: CompilerContext,
module: BasilispModule,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> None:
"""Compile an entire Basilisp module into Python bytecode which can be
executed as a Python module.
Expand Down Expand Up @@ -298,7 +298,7 @@ def load(
path: str,
ctx: CompilerContext,
ns: runtime.Namespace,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> Any:
"""Call :lpy:fn:`basilisp.core/load` with the given ``path``, returning the
result."""
Expand All @@ -311,7 +311,7 @@ def load_file(
path: Path,
ctx: CompilerContext,
ns: runtime.Namespace,
collect_bytecode: Optional[BytecodeCollector] = None,
collect_bytecode: BytecodeCollector | None = None,
) -> Any:
"""Call :lpy:fn:`basilisp.core/load-file` with the given ``path``, returning the
result."""
Expand Down
Loading