Skip to content

Commit

Permalink
Remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
lycantropos committed Oct 30, 2023
1 parent d8fed87 commit e20ee35
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 182 deletions.
25 changes: 2 additions & 23 deletions paradigm/_core/annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,8 @@ def _(left: t.Union[bytes, str], right: t.Any) -> bool:
return result


if sys.version_info >= (3, 8):
to_arguments = t.get_args
to_origin = t.get_origin
else:
def to_arguments(annotation: t.Any) -> t.Tuple[t.Any, ...]:
if isinstance(annotation, GenericAlias):
result = annotation.__args__
if (result
and to_origin(annotation) is abc.Callable
and result[0] is not Ellipsis):
result = (list(result[:-1]), result[-1])
assert isinstance(result, tuple)
return result
return ()


def to_origin(annotation: t.Any) -> t.Any:
if isinstance(annotation, GenericAlias):
return annotation.__origin__
elif annotation is t.Generic:
return t.Generic
else:
return None
to_arguments = t.get_args
to_origin = t.get_origin


@singledispatch
Expand Down
14 changes: 5 additions & 9 deletions paradigm/_core/arboreal/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
from .conversion import RawAstNode

_AST_NAMESPACE = vars(ast).copy()
if sys.version_info >= (3, 8):
del _AST_NAMESPACE[ast.Ellipsis.__qualname__]

if sys.version_info < (3, 8):
def from_node(ast_node: ast.AST) -> ast.Module:
return ast.Module([ast_node])
else:
def from_node(ast_node: ast.AST) -> ast.Module:
return ast.Module([ast_node], [])
del _AST_NAMESPACE[ast.Ellipsis.__qualname__]


def from_node(ast_node: ast.AST) -> ast.Module:
return ast.Module([ast_node], [])


def from_raw(raw: RawAstNode,
Expand Down
19 changes: 0 additions & 19 deletions paradigm/_core/arboreal/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,6 @@ def _(ast_node: ast.List) -> str:
return f'[{", ".join(elements_strings)}]'


if sys.version_info < (3, 8):
@to_str.register(ast.Ellipsis)
def _(ast_node: ast.Ellipsis) -> str:
return str(Ellipsis)

@to_str.register(ast.NameConstant)
def _(ast_node: ast.NameConstant) -> str:
return str(ast_node.value)


@to_str.register(ast.Num)
def _(ast_node: ast.Num) -> str:
return str(ast_node.n)


@to_str.register(ast.Str)
def _(ast_node: ast.Str) -> str:
return ast_node.s

if sys.version_info < (3, 10):
@to_str.register(ast.BinOp)
def _(ast_node: ast.BinOp) -> str:
Expand Down
52 changes: 6 additions & 46 deletions paradigm/_core/arboreal/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,12 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> ast.FunctionDef:
self.generic_visit(node)
return node

if sys.version_info < (3, 8):
def visit_arg(self, node: ast.arg) -> ast.arg:
return ast.arg(node.arg,
None
if node.annotation is None
else ast.Str(conversion.to_str(node.annotation)))
else:
def visit_arg(self, node: ast.arg) -> ast.arg:
return ast.arg(node.arg,
None
if node.annotation is None
else ast.Str(conversion.to_str(node.annotation)),
getattr(node, 'type_comment', None))
def visit_arg(self, node: ast.arg) -> ast.arg:
return ast.arg(node.arg,
None
if node.annotation is None
else ast.Str(conversion.to_str(node.annotation)),
getattr(node, 'type_comment', None))


_AstNode = t.TypeVar('_AstNode',
Expand Down Expand Up @@ -437,39 +430,6 @@ def evaluate_qualified_path(
return result


if sys.version_info < (3, 8):
@evaluate_expression_node.register(ast.Ellipsis)
def _(ast_node: ast.Ellipsis,
module_path: catalog.Path,
parent_path: catalog.Path,
parent_namespace: namespacing.Namespace) -> t.Any:
return Ellipsis


@evaluate_expression_node.register(ast.NameConstant)
def _(ast_node: ast.NameConstant,
module_path: catalog.Path,
parent_path: catalog.Path,
parent_namespace: namespacing.Namespace) -> t.Any:
return ast_node.value


@evaluate_expression_node.register(ast.Num)
def _(ast_node: ast.Num,
module_path: catalog.Path,
parent_path: catalog.Path,
parent_namespace: namespacing.Namespace) -> t.Any:
return ast_node.n


@evaluate_expression_node.register(ast.Bytes)
@evaluate_expression_node.register(ast.Str)
def _(ast_node: ast.Str,
module_path: catalog.Path,
parent_path: catalog.Path,
parent_namespace: namespacing.Namespace) -> t.Any:
return ast_node.s

if sys.version_info < (3, 9):
_GenericAlias: t.Any = type(t.List)
_types_to_generic_aliases = {value.__origin__: value
Expand Down
15 changes: 5 additions & 10 deletions paradigm/_core/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,12 @@ def _recursively_update_modules_paths(
'encodings.mbcs',
'encodings.oem',
'multiprocessing.popen_spawn_win32')
if sys.version_info < (3, 8):
_recursively_update_modules_paths(unsupported_stdlib_modules_paths,
'distutils._msvccompiler',
'encodings.cp65001')
if sys.platform == 'darwin':
if sys.version_info >= (3, 8):
_recursively_update_modules_paths(
unsupported_stdlib_modules_paths,
'dbm.gnu',
'distutils._msvccompiler',
)
_recursively_update_modules_paths(
unsupported_stdlib_modules_paths,
'dbm.gnu',
'distutils._msvccompiler',
)

supported_stdlib_modules_paths: Final[t.Iterable[catalog.Path]] = [
module_path
Expand Down
34 changes: 11 additions & 23 deletions paradigm/_core/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,17 @@ def _named_tuple_to_constructor_ast_node(
)


if _sys.version_info < (3, 8):
def _annotations_to_signature(
ast_nodes: _t.List[_ast.AnnAssign]
) -> _ast.arguments:
return _ast.arguments([_ast.arg('cls', None)]
+ [_ann_assign_to_arg(ast_node)
for ast_node in ast_nodes],
None, [], [], None,
[ast_node.value
for ast_node in ast_nodes
if ast_node.value is not None])
else:
def _annotations_to_signature(
ast_nodes: _t.List[_ast.AnnAssign]
) -> _ast.arguments:
return _ast.arguments([],
[_ast.arg('cls', None)]
+ [_ann_assign_to_arg(ast_node)
for ast_node in ast_nodes],
None, [], [], None,
[ast_node.value
for ast_node in ast_nodes
if ast_node.value is not None])
def _annotations_to_signature(
ast_nodes: _t.List[_ast.AnnAssign]
) -> _ast.arguments:
return _ast.arguments([],
[_ast.arg('cls', None)]
+ [_ann_assign_to_arg(ast_node)
for ast_node in ast_nodes],
None, [], [], None,
[ast_node.value
for ast_node in ast_nodes
if ast_node.value is not None])


def _ann_assign_to_arg(ast_node: _ast.AnnAssign) -> _ast.arg:
Expand Down
53 changes: 1 addition & 52 deletions paradigm/_core/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import functools
import sys
import typing as t

import typing_extensions as te
Expand All @@ -18,57 +17,7 @@ def decorate_if(
return decorator if condition else _identity_decorator


singledispatchmethod: t.Any
if sys.version_info < (3, 8):

class _singledispatchmethod:
dispatcher: t.Any
func: t.Callable[..., _T1]

def __new__(cls, func: t.Callable[..., t.Any]) -> te.Self:
if not callable(func) and not hasattr(func, '__get__'):
raise TypeError(f'{func!r} is not callable or a descriptor')
self = super().__new__(cls)
self.dispatcher, self.func = functools.singledispatch(func), func
return self

@t.overload
def register(self,
cls: t.Type[t.Any],
method: t.Callable[..., _T1]) -> t.Any:
return self.dispatcher.register(cls, method)

@t.overload
def register(self, cls: t.Type[t.Any]) -> t.Any:
return self.dispatcher.register(cls)

def register(self,
cls: t.Type[t.Any],
method: t.Optional[t.Callable[..., _T1]] = None) -> t.Any:
return self.dispatcher.register(cls, method)

@property
def __isabstractmethod__(self) -> bool:
return getattr(self.func, '__isabstractmethod__', False)

def __get__(self,
instance: _T2,
cls: t.Optional[_T2] = None) -> t.Any:
def dispatchable_method(*args: t.Any,
**kwargs: t.Any) -> t.Any:
method = self.dispatcher.dispatch(args[0].__class__)
return method.__get__(instance, cls)(*args, **kwargs)

result: t.Any = dispatchable_method
result.__isabstractmethod__ = self.__isabstractmethod__
result.register = self.register
functools.update_wrapper(result, self.func)
return result


singledispatchmethod = _singledispatchmethod
else:
singledispatchmethod = functools.singledispatchmethod
singledispatchmethod = functools.singledispatchmethod


def _identity_decorator(
Expand Down

0 comments on commit e20ee35

Please sign in to comment.