Skip to content

Commit

Permalink
fix ruff lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zerlok committed Nov 26, 2024
1 parent 0fadd30 commit 5507880
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 20 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ build-backend = "poetry.core.masonry.api"


[tool.ruff]
target-version = "py39"
include = ["src/**/*.py", "tests/**/*.py"]
extend-exclude = ["tests/**/expected_gen/**.py"]
force-exclude = true
Expand Down
6 changes: 3 additions & 3 deletions src/pyprotostuben/codegen/mypy/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __build_protobuf_message_has_field_method_stub(self, scope: ScopeInfo) -> as
)

def __build_which_oneof_method_stubs(self, scope: ScopeInfo) -> t.Iterable[ast.stmt]:
oneofs: t.DefaultDict[str, t.List[ast.expr]] = defaultdict(list)
oneofs = defaultdict[str, list[ast.expr]](list)
for field in scope.fields:
if field.oneof_group is not None:
oneofs[field.oneof_group].append(self.__inner.build_const(field.name))
Expand Down Expand Up @@ -429,7 +429,7 @@ def __build_stub_method_def(self, info: MethodInfo) -> ast.stmt:
doc=info.doc,
)

def __build_servicer_method_inout_refs(self, info: MethodInfo) -> t.Tuple[ast.expr, ast.expr]:
def __build_servicer_method_inout_refs(self, info: MethodInfo) -> tuple[ast.expr, ast.expr]:
if not info.server_input_streaming and not info.server_output_streaming:
return (
self.__build_message_ref(info.server_input),
Expand Down Expand Up @@ -457,7 +457,7 @@ def __build_servicer_method_inout_refs(self, info: MethodInfo) -> t.Tuple[ast.ex
msg = "invalid method streaming options"
raise ValueError(msg, info)

def __build_stub_method_inout_refs(self, info: MethodInfo) -> t.Tuple[ast.expr, ast.expr]:
def __build_stub_method_inout_refs(self, info: MethodInfo) -> tuple[ast.expr, ast.expr]:
if not info.server_input_streaming and not info.server_output_streaming:
return (
self.__build_message_ref(info.server_input),
Expand Down
7 changes: 4 additions & 3 deletions src/pyprotostuben/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ def configure(cls) -> None:
def get(
# allow callee to pass custom `cls` kwarg
__cls, # noqa: N804
__name: str,
name: str,
/,
**kwargs: object,
) -> "Logger":
return __cls(getLogger(__name), kwargs)
return __cls(getLogger(name), kwargs)

def process(
self,
msg: object,
kwargs: t.MutableMapping[str, object],
) -> t.Tuple[object, t.MutableMapping[str, object]]:
) -> tuple[object, t.MutableMapping[str, object]]:
exc_info = kwargs.pop("exc_info", None)
return msg, {
"exc_info": exc_info,
Expand Down
8 changes: 4 additions & 4 deletions src/pyprotostuben/protobuf/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class CodeGeneratorContext:

@dataclass()
class BuildContext:
files: t.Dict[str, ProtoFile] = field(default_factory=dict)
types: t.Dict[str, t.Union[EnumInfo, MessageInfo]] = field(default_factory=dict)
map_entries: t.Dict[str, MapEntryPlaceholder] = field(default_factory=dict)
files: dict[str, ProtoFile] = field(default_factory=dict)
types: dict[str, t.Union[EnumInfo, MessageInfo]] = field(default_factory=dict)
map_entries: dict[str, MapEntryPlaceholder] = field(default_factory=dict)


class ContextBuilder(ProtoVisitor[BuildContext], LoggerMixin):
Expand Down Expand Up @@ -141,7 +141,7 @@ def __build_type(
EnumContext[BuildContext],
DescriptorContext[BuildContext],
],
) -> t.Tuple[str, ModuleInfo, t.Sequence[str]]:
) -> tuple[str, ModuleInfo, t.Sequence[str]]:
ns = [part.proto.name for part in context.parts[1:]]
proto_path = ".".join(ns)

Expand Down
2 changes: 1 addition & 1 deletion src/pyprotostuben/protobuf/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def get_comment_blocks(location: t.Optional[SourceCodeInfo.Location]) -> t.Seque
if location is None:
return []

blocks: t.List[str] = []
blocks: list[str] = []
blocks.extend(comment.strip() for comment in location.leading_detached_comments)

if location.HasField("leading_comments"):
Expand Down
12 changes: 6 additions & 6 deletions src/pyprotostuben/python/ast_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def get_dependencies(self) -> t.Sequence[ModuleInfo]:
class ModuleDependencyResolver(DependencyResolver):
def __init__(self, module: ModuleInfo) -> None:
self.__module = module
self.__deps: t.Set[ModuleInfo] = set()
self.__deps: set[ModuleInfo] = set()

def resolve(self, info: TypeInfo) -> TypeInfo:
if info.module == self.__module:
Expand Down Expand Up @@ -508,7 +508,7 @@ def build_call_stmt(
def build_with_stmt(
self,
*,
items: t.Sequence[t.Tuple[str, TypeRef]],
items: t.Sequence[tuple[str, TypeRef]],
body: t.Sequence[ast.stmt],
is_async: bool = False,
) -> t.Union[ast.With, ast.AsyncWith]:
Expand Down Expand Up @@ -660,7 +660,7 @@ def build_module(
def _build_decorators(
self,
*decorators: t.Optional[t.Sequence[t.Union[ast.expr, TypeInfo, None]]],
) -> t.List[ast.expr]:
) -> list[ast.expr]:
return [
self.build_ref(dec) for block in (decorators or ()) if block for dec in (block or ()) if dec is not None
]
Expand Down Expand Up @@ -696,14 +696,14 @@ def _build_func_args(self, args: t.Optional[t.Sequence[FuncArgInfo]]) -> ast.arg
],
)

def _build_body(self, doc: t.Optional[str], body: t.Optional[t.Sequence[ast.stmt]]) -> t.List[ast.stmt]:
result: t.List[ast.stmt] = list(body or ())
def _build_body(self, doc: t.Optional[str], body: t.Optional[t.Sequence[ast.stmt]]) -> list[ast.stmt]:
result: list[ast.stmt] = list(body or ())
if doc:
result.insert(0, self.build_docstring(doc))

return result

def _build_stub_body(self, doc: t.Optional[str]) -> t.List[ast.stmt]:
def _build_stub_body(self, doc: t.Optional[str]) -> list[ast.stmt]:
return (
[
ast.Expr(value=ast.Constant(value=...)),
Expand Down
2 changes: 1 addition & 1 deletion src/pyprotostuben/python/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def from_str(cls, ref: str) -> "TypeInfo":
return cls(ModuleInfo.from_str(module), ns.split("."))

@classmethod
def from_type(cls, type_: t.Type[object]) -> "TypeInfo":
def from_type(cls, type_: type[object]) -> "TypeInfo":
return cls(ModuleInfo.from_str(type_.__module__), type_.__qualname__.split("."))

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion src/pyprotostuben/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_last(self) -> V_co:

class MutableStack(Stack[T]):
def __init__(self, items: t.Optional[t.Sequence[T]] = None) -> None:
self.__impl: t.Deque[T] = deque(items or [])
self.__impl = deque[T](items or [])

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.__impl!r})"
Expand Down
2 changes: 1 addition & 1 deletion tests/stub/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CustomPluginError(Exception):

class ProtocPluginStub(ProtocPlugin):
def __init__(self, side_effect: t.Optional[Exception], return_value: t.Optional[CodeGeneratorResponse]) -> None:
self.requests: t.List[CodeGeneratorRequest] = []
self.requests: list[CodeGeneratorRequest] = []
self.__side_effect = side_effect
self.__return_value = return_value

Expand Down

0 comments on commit 5507880

Please sign in to comment.