Skip to content

TYP: annotation of __init__ return type (PEP 484) (pandas/core/computation) #46254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2022
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
2 changes: 1 addition & 1 deletion pandas/core/computation/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AbstractEngine(metaclass=abc.ABCMeta):

has_neg_frac = False

def __init__(self, expr):
def __init__(self, expr) -> None:
self.expr = expr
self.aligned_axes = None
self.result_type = None
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/computation/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class BaseExprVisitor(ast.NodeVisitor):

unsupported_nodes: tuple[str, ...]

def __init__(self, env, engine, parser, preparser=_preparse):
def __init__(self, env, engine, parser, preparser=_preparse) -> None:
self.env = env
self.engine = engine
self.parser = parser
Expand Down Expand Up @@ -768,13 +768,13 @@ def __init__(
_preparse,
f=_compose(_replace_locals, _replace_booleans, clean_backtick_quoted_toks),
),
):
) -> None:
super().__init__(env, engine, parser, preparser)


@disallow(_unsupported_nodes | _python_not_supported | frozenset(["Not"]))
class PythonExprVisitor(BaseExprVisitor):
def __init__(self, env, engine, parser, preparser=lambda x: x):
def __init__(self, env, engine, parser, preparser=lambda x: x) -> None:
super().__init__(env, engine, parser, preparser=preparser)


Expand Down Expand Up @@ -802,7 +802,7 @@ def __init__(
parser: str = "pandas",
env: Scope | None = None,
level: int = 0,
):
) -> None:
self.expr = expr
self.env = env or Scope(level=level + 1)
self.engine = engine
Expand Down
18 changes: 9 additions & 9 deletions pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class UndefinedVariableError(NameError):
NameError subclass for local variables.
"""

def __init__(self, name: str, is_local: bool | None = None):
def __init__(self, name: str, is_local: bool | None = None) -> None:
base_msg = f"{repr(name)} is not defined"
if is_local:
msg = f"local variable {base_msg}"
Expand All @@ -88,7 +88,7 @@ def __new__(cls, name, env, side=None, encoding=None):

is_local: bool

def __init__(self, name, env, side=None, encoding=None):
def __init__(self, name, env, side=None, encoding=None) -> None:
# name is a str for Term, but may be something else for subclasses
self._name = name
self.env = env
Expand Down Expand Up @@ -189,7 +189,7 @@ def ndim(self) -> int:


class Constant(Term):
def __init__(self, value, env, side=None, encoding=None):
def __init__(self, value, env, side=None, encoding=None) -> None:
super().__init__(value, env, side=side, encoding=encoding)

def _resolve_name(self):
Expand All @@ -215,7 +215,7 @@ class Op:

op: str

def __init__(self, op: str, operands: Iterable[Term | Op], encoding=None):
def __init__(self, op: str, operands: Iterable[Term | Op], encoding=None) -> None:
self.op = _bool_op_map.get(op, op)
self.operands = operands
self.encoding = encoding
Expand Down Expand Up @@ -375,7 +375,7 @@ class BinOp(Op):
rhs : Term or Op
"""

def __init__(self, op: str, lhs, rhs):
def __init__(self, op: str, lhs, rhs) -> None:
super().__init__(op, (lhs, rhs))
self.lhs = lhs
self.rhs = rhs
Expand Down Expand Up @@ -530,7 +530,7 @@ class Div(BinOp):
The Terms or Ops in the ``/`` expression.
"""

def __init__(self, lhs, rhs):
def __init__(self, lhs, rhs) -> None:
super().__init__("/", lhs, rhs)

if not isnumeric(lhs.return_type) or not isnumeric(rhs.return_type):
Expand Down Expand Up @@ -566,7 +566,7 @@ class UnaryOp(Op):
* If no function associated with the passed operator token is found.
"""

def __init__(self, op: str, operand):
def __init__(self, op: str, operand) -> None:
super().__init__(op, (operand,))
self.operand = operand

Expand Down Expand Up @@ -598,7 +598,7 @@ def return_type(self) -> np.dtype:


class MathCall(Op):
def __init__(self, func, args):
def __init__(self, func, args) -> None:
super().__init__(func.name, args)
self.func = func

Expand All @@ -614,7 +614,7 @@ def __repr__(self) -> str:


class FuncNode:
def __init__(self, name: str):
def __init__(self, name: str) -> None:
if name not in MATHOPS:
raise ValueError(f'"{name}" is not a supported function')
self.name = name
Expand Down
14 changes: 7 additions & 7 deletions pandas/core/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(
global_dict=None,
local_dict=None,
queryables: dict[str, Any] | None = None,
):
) -> None:
super().__init__(level + 1, global_dict=global_dict, local_dict=local_dict)
self.queryables = queryables or {}

Expand All @@ -63,7 +63,7 @@ def __new__(cls, name, env, side=None, encoding=None):
klass = Constant
return object.__new__(klass)

def __init__(self, name, env: PyTablesScope, side=None, encoding=None):
def __init__(self, name, env: PyTablesScope, side=None, encoding=None) -> None:
super().__init__(name, env, side=side, encoding=encoding)

def _resolve_name(self):
Expand All @@ -87,7 +87,7 @@ def value(self):


class Constant(Term):
def __init__(self, value, env: PyTablesScope, side=None, encoding=None):
def __init__(self, value, env: PyTablesScope, side=None, encoding=None) -> None:
assert isinstance(env, PyTablesScope), type(env)
super().__init__(value, env, side=side, encoding=encoding)

Expand All @@ -103,7 +103,7 @@ class BinOp(ops.BinOp):
queryables: dict[str, Any]
condition: str | None

def __init__(self, op: str, lhs, rhs, queryables: dict[str, Any], encoding):
def __init__(self, op: str, lhs, rhs, queryables: dict[str, Any], encoding) -> None:
super().__init__(op, lhs, rhs)
self.queryables = queryables
self.encoding = encoding
Expand Down Expand Up @@ -407,7 +407,7 @@ class PyTablesExprVisitor(BaseExprVisitor):
const_type = Constant
term_type = Term

def __init__(self, env, engine, parser, **kwargs):
def __init__(self, env, engine, parser, **kwargs) -> None:
super().__init__(env, engine, parser)
for bin_op in self.binary_ops:
bin_node = self.binary_op_nodes_map[bin_op]
Expand Down Expand Up @@ -552,7 +552,7 @@ def __init__(
queryables: dict[str, Any] | None = None,
encoding=None,
scope_level: int = 0,
):
) -> None:

where = _validate_where(where)

Expand Down Expand Up @@ -624,7 +624,7 @@ def evaluate(self):
class TermValue:
"""hold a term value the we use to construct a condition/filter"""

def __init__(self, value, converted, kind: str):
def __init__(self, value, converted, kind: str) -> None:
assert isinstance(kind, str), kind
self.value = value
self.converted = converted
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class Scope:

def __init__(
self, level: int, global_dict=None, local_dict=None, resolvers=(), target=None
):
) -> None:
self.level = level + 1

# shallow copy because we don't want to keep filling this up with what
Expand Down