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
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ help:
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

clean: ## Removing cached python compiled files
find . -name \*pyc | xargs rm -fv
find . -name \*pyo | xargs rm -fv
find . -name \*~ | xargs rm -fv
find . -name __pycache__ | xargs rm -rfv
find . -name .ruff_cache | xargs rm -rfv
find . -name "*.pyc" -type f -delete
find . -name "*.pyo" -type f -delete
find . -name "*~" -type f -delete
find . -name "__pycache__" -type d -exec rm -rf {} + 2>/dev/null || true
find . -name ".ruff_cache" -type d -exec rm -rf {} + 2>/dev/null || true

install: ## Install dependencies
pip install -r requirements.txt
Expand Down
2 changes: 1 addition & 1 deletion ellar/app/lifespan.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async def lifespan(self, app: "App") -> t.AsyncIterator[t.Any]:
logger.debug("Executing Modules Startup Handlers")
await self.run_all_startup_actions(app)

async with self._lifespan_context(app) as ctx: # type:ignore[attr-defined]
async with self._lifespan_context(app) as ctx:
logger.info("Application is ready.")
yield ctx
finally:
Expand Down
8 changes: 4 additions & 4 deletions ellar/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def __init__(
):
_routes = routes or []
assert isinstance(config, Config), "config must instance of Config"
assert isinstance(
injector, EllarInjector
), "injector must instance of EllarInjector"
assert isinstance(injector, EllarInjector), (
"injector must instance of EllarInjector"
)

self._config = config
self._injector: EllarInjector = injector
Expand All @@ -70,7 +70,7 @@ def __init__(
redirect_slashes=self.config.REDIRECT_SLASHES,
default=self.config.DEFAULT_NOT_FOUND_HANDLER,
lifespan=EllarApplicationLifespan(
self.config.DEFAULT_LIFESPAN_HANDLER # type: ignore[arg-type]
self.config.DEFAULT_LIFESPAN_HANDLER
).lifespan,
)

Expand Down
2 changes: 1 addition & 1 deletion ellar/auth/handlers/schemes/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _get_credentials(self, connection: "HTTPConnection") -> HTTPBasicCredentials

if not separator:
self._not_unauthorized_exception("Invalid authentication credentials")
return HTTPBasicCredentials(username=username, password=password) # type: ignore[arg-type]
return HTTPBasicCredentials(username=username, password=password)


class HttpDigestAuth(HttpBearerAuth, ABC):
Expand Down
2 changes: 1 addition & 1 deletion ellar/auth/policy/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MyPolicyHandler(PolicyWithRequirement):
"""

def __init__(self, *args: t.Any) -> None:
kwargs_args = {f"arg_{idx+1}": value for idx, value in enumerate(args)}
kwargs_args = {f"arg_{idx + 1}": value for idx, value in enumerate(args)}
super().__init__(kwargs_args)


Expand Down
2 changes: 1 addition & 1 deletion ellar/cache/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setup(
args = {"default": default}
args.update(kwargs)

schema = CacheModuleSchemaSetup(**{"CACHES": args}) # type: ignore[arg-type]
schema = CacheModuleSchemaSetup(**{"CACHES": args})
return cls._create_dynamic_module(schema)

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions ellar/cache/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def __init__(
self, backends: t.Optional[t.Dict[str, BaseCacheBackend]] = None
) -> None:
if backends:
assert backends.get(
"default"
), "CACHES configuration must have a 'default' key."
assert backends.get("default"), (
"CACHES configuration must have a 'default' key."
)
self._backends = backends or {
"default": LocalMemCacheBackend(key_prefix="ellar", version=1, ttl=300)
}
Expand Down
6 changes: 3 additions & 3 deletions ellar/common/decorators/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def Controller(
_prefix = NOT_SET

if _prefix is not NOT_SET:
assert _prefix == "" or str(_prefix).startswith(
"/"
), "Controller Prefix must start with '/'"
assert _prefix == "" or str(_prefix).startswith("/"), (
"Controller Prefix must start with '/'"
)
# TODO: replace with a ControllerTypeDict and OpenAPITypeDict
kwargs = AttributeDict(
path=_prefix,
Expand Down
6 changes: 3 additions & 3 deletions ellar/common/decorators/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def render(template_name: t.Optional[str] = NOT_SET) -> t.Callable:
:return:
"""
if template_name is not NOT_SET:
assert isinstance(
template_name, str
), "Render Operation must invoked eg. @render()"
assert isinstance(template_name, str), (
"Render Operation must invoked eg. @render()"
)
template_name = None if template_name is NOT_SET else template_name

def _decorator(func: t.Union[t.Callable, t.Any]) -> t.Union[t.Callable, t.Any]:
Expand Down
2 changes: 1 addition & 1 deletion ellar/common/decorators/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def Module(

:return: t.TYPE[ModuleBase]
"""
base_directory = get_main_directory_by_stack(base_directory, stack_level=2) # type:ignore[arg-type]
base_directory = get_main_directory_by_stack(base_directory, stack_level=2)
kwargs = AttributeDict(
name=name,
controllers=list(controllers),
Expand Down
12 changes: 6 additions & 6 deletions ellar/common/interfaces/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ async def catch(self, ctx: IHostContext, exc: t.Any) -> t.Union[Response, t.Any]
"""Catch implementation"""

def __init_subclass__(cls, **kwargs: t.Any) -> None:
assert (
cls.exception_type_or_code
), f"'exception_type_or_code' must be defined. {cls}"
assert cls.exception_type_or_code, (
f"'exception_type_or_code' must be defined. {cls}"
)
if not isinstance(cls.exception_type_or_code, int):
assert issubclass(
cls.exception_type_or_code, Exception
), "'exception_type_or_code' is not a valid type"
assert issubclass(cls.exception_type_or_code, Exception), (
"'exception_type_or_code' is not a valid type"
)


class IExceptionMiddlewareService:
Expand Down
14 changes: 7 additions & 7 deletions ellar/common/params/args/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ def get_convertor_model_field(
cls, param_name: str, convertor: Convertor
) -> ModelField:
_converter_signature = inspect.signature(convertor.convert)
assert (
_converter_signature.return_annotation is not inspect.Parameter.empty
), f"{convertor.__class__.__name__} Convertor must have return type"
assert _converter_signature.return_annotation is not inspect.Parameter.empty, (
f"{convertor.__class__.__name__} Convertor must have return type"
)
_type = _converter_signature.return_annotation
return get_parameter_field(
param_default=params.PathFieldInfo(),
Expand Down Expand Up @@ -280,9 +280,9 @@ def compute_route_parameter_list(
default_field_info=params.PathFieldInfo,
ignore_default=ignore_default,
)
assert is_scalar_field(
field=param_field
), "Path params must be of one of the supported types"
assert is_scalar_field(field=param_field), (
"Path params must be of one of the supported types"
)
self._add_to_model(field=param_field)
else:
param_field = process_parameter_file(
Expand All @@ -302,7 +302,7 @@ def _add_system_parameters_to_dependency(
key: t.Optional[str] = None,
) -> t.Optional[bool]:
if isinstance(param_default, SystemParameterResolver):
model = param_default(param_name, param_annotation) # type:ignore
model = param_default(param_name, param_annotation)
self._computation_models[key or model.in_].append(model)
return True
return None
Expand Down
2 changes: 1 addition & 1 deletion ellar/common/params/args/resolver_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def generate_resolvers(self, body_field_class: t.Type[FieldInfo]) -> None:
for k, field in self.pydantic_outer_type.model_fields.items():
model_field = create_model_field(
name=k,
type_=field.annotation, # type:ignore[arg-type]
type_=field.annotation,
default=field.default,
alias=field.alias,
field_info=field,
Expand Down
10 changes: 5 additions & 5 deletions ellar/common/params/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ def create_resolver(
Returns:
BaseRouteParameterResolver: The created resolver.
"""
multiple_resolvers = model_field.field_info.json_schema_extra.pop( # type:ignore[union-attr]
multiple_resolvers = model_field.field_info.json_schema_extra.pop(
MULTI_RESOLVER_KEY, None
)
if multiple_resolvers:
return self.bulk_resolver(
model_field=model_field,
resolvers=multiple_resolvers, # type:ignore[arg-type]
resolvers=multiple_resolvers,
)
return self.resolver(model_field)

Expand Down Expand Up @@ -440,17 +440,17 @@ def __init__(
def create_resolver(
self, model_field: ModelField
) -> t.Union[BaseRouteParameterResolver, IRouteParameterResolver]:
multiple_resolvers = model_field.field_info.json_schema_extra.pop( # type:ignore[union-attr]
multiple_resolvers = model_field.field_info.json_schema_extra.pop(
MULTI_RESOLVER_KEY, []
)
is_grouped = model_field.field_info.json_schema_extra.pop( # type:ignore[union-attr]
is_grouped = model_field.field_info.json_schema_extra.pop(
MULTI_RESOLVER_FORM_GROUPED_KEY, False
)

if multiple_resolvers:
return self.bulk_resolver(
model_field=model_field,
resolvers=multiple_resolvers, # type:ignore[arg-type]
resolvers=multiple_resolvers,
is_grouped=is_grouped,
)
return self.resolver(model_field)
Expand Down
8 changes: 4 additions & 4 deletions ellar/common/params/resolvers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def assert_field_info(self) -> None:
"""
from .. import params

assert isinstance(
self.model_field.field_info, params.ParamFieldInfo
), "Params must be subclasses of Param"
assert isinstance(self.model_field.field_info, params.ParamFieldInfo), (
"Params must be subclasses of Param"
)

@classmethod
def create_error(cls, loc: t.Any) -> t.Any:
Expand All @@ -92,7 +92,7 @@ def validate_error_sequence(cls, errors: t.Any) -> t.List[t.Any]:

async def resolve(self, *args: t.Any, **kwargs: t.Any) -> ResolverResult:
value_ = await self.resolve_handle(*args, **kwargs)
return value_
return t.cast(ResolverResult, value_)

@abstractmethod
@t.no_type_check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ async def resolve(self, ctx: IExecutionContext, **kwargs: t.Any) -> ResolverResu
background_tasks = BackgroundTasks()

if res.background and isinstance(res.background, BackgroundTask):
background_tasks.add_task(res.background.func)
background_tasks.add_task(
res.background.func, *res.background.args, **res.background.kwargs
)

res.background = background_tasks

Expand Down
4 changes: 1 addition & 3 deletions ellar/common/responses/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def validate_object(self, obj: t.Any) -> t.Any:
)
values, error = self.validate(obj, {}, loc=(self.alias,))
if error:
_errors = (
list(error) if isinstance(error, list) else [error] # type:ignore[list-item]
)
_errors = list(error) if isinstance(error, list) else [error]
return None, _errors
return values, []

Expand Down
2 changes: 1 addition & 1 deletion ellar/common/responses/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def create_response(
)

init_kwargs = self.serialize(response_obj)
response_args.update(init_kwargs) # type:ignore[arg-type]
response_args.update(init_kwargs)

response = self._response_type(
**response_args,
Expand Down
6 changes: 3 additions & 3 deletions ellar/common/responses/models/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ def convert_route_responses_to_response_models(
) -> None:
self.validate_route_response(route_responses)
for status_code, response_schema in route_responses.items():
assert (
isinstance(status_code, int) or status_code == Ellipsis
), "status_code must be a number"
assert isinstance(status_code, int) or status_code == Ellipsis, (
"status_code must be a number"
)
description: str = "Successful Response"
if isinstance(response_schema, (tuple, list)):
response_schema, description = response_schema
Expand Down
2 changes: 1 addition & 1 deletion ellar/common/serializer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def serialize_object(
return serialize_object(obj_dict, _encoders)
if is_dataclass(obj):
return serialize_object(
asdict(obj), # type:ignore[call-overload]
asdict(obj),
encoders=_encoders,
serializer_filter=serializer_filter,
)
Expand Down
2 changes: 1 addition & 1 deletion ellar/core/conf/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _load_config_module(self, prefix: str) -> dict:
return data

def __repr__(self) -> str: # pragma: no cover
hidden_values = {key: "..." for key in self._schema.serialize().keys()}
hidden_values = dict.fromkeys(self._schema.serialize().keys(), "...")
return f"<Configuration {repr(hidden_values)}, settings_module: {self._config_module}>"

def __str__(self) -> str:
Expand Down
4 changes: 2 additions & 2 deletions ellar/core/exceptions/callable_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ async def catch(
) -> t.Union[Response, t.Any]:
args = tuple(list(self.func_args) + [ctx, exc])
if self.is_async:
return await self.callable_exception_handler(*args) # type:ignore[misc]
return await run_in_threadpool(self.callable_exception_handler, *args) # type:ignore[arg-type]
return await self.callable_exception_handler(*args) # type: ignore[misc]
return await run_in_threadpool(self.callable_exception_handler, *args)

def __eq__(self, other: t.Any) -> bool:
if isinstance(other, CallableExceptionHandler):
Expand Down
6 changes: 3 additions & 3 deletions ellar/core/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def get_module_ref(self, config: "Config", container: Container) -> ModuleRefBas
self.module, config, container, **self.init_kwargs
)

assert isinstance(
ref, ModuleRefBase
), f"{ref.module} is not properly configured."
assert isinstance(ref, ModuleRefBase), (
f"{ref.module} is not properly configured."
)

ref.initiate_module_build()
return ref
Expand Down
6 changes: 3 additions & 3 deletions ellar/core/modules/ref/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ def _validate_() -> None:
and data.parent == self.module
)
)
assert (
module
), f"Unknown Export '{provider_type}' found in '{self.module}'"
assert module, (
f"Unknown Export '{provider_type}' found in '{self.module}'"
)

_validate_()

Expand Down
6 changes: 3 additions & 3 deletions ellar/core/modules/ref/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ def create_module_ref_factor(
)
return module_ref
elif type(module_type) is ModuleBaseMeta:
assert (
container is not None
), "ModulePlainRef class can't take a nullable 'container'"
assert container is not None, (
"ModulePlainRef class can't take a nullable 'container'"
)

module_ref = ModulePlainRef(
module_type,
Expand Down
6 changes: 3 additions & 3 deletions ellar/core/modules/ref/plain.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ def __init__(
self._register_module()

def _validate_module_type(self) -> None:
assert (
type(self.module) is ModuleBaseMeta
), f"Module Type must be a subclass of ModuleBase;\n Invalid Type[{self.module}]"
assert type(self.module) is ModuleBaseMeta, (
f"Module Type must be a subclass of ModuleBase;\n Invalid Type[{self.module}]"
)

def _register_module(self) -> None:
if not is_decorated_with_injectable(self.module):
Expand Down
6 changes: 3 additions & 3 deletions ellar/core/modules/ref/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def initiate_module_build(self) -> None:

def _validate_module_type(self) -> None:
res = reflect.get_metadata(MODULE_WATERMARK, self.module)
assert (
res is True
), f"Module Type must be decorated with @Module decorator;\n Invalid Module type[{self.module}]"
assert res is True, (
f"Module Type must be decorated with @Module decorator;\n Invalid Module type[{self.module}]"
)

def _register_module(self) -> None:
self.add_provider(
Expand Down
Loading