From 52123aeb1bcd8d37f6a54de1a8d95a8b06731f7e Mon Sep 17 00:00:00 2001 From: Kumaran Rajendhiran Date: Fri, 16 Aug 2024 11:27:55 +0530 Subject: [PATCH] Remove unused ignores (#1690) * Remove unused ignores * Add misc ignore comments and remove cast * Revert cast change --- faststream/_compat.py | 6 +++--- faststream/asyncapi/message.py | 4 ++-- faststream/asyncapi/schema/info.py | 2 +- faststream/broker/fastapi/get_dependant.py | 4 ++-- faststream/broker/fastapi/route.py | 4 ++-- faststream/broker/fastapi/router.py | 4 ++-- faststream/broker/publisher/usecase.py | 4 ++-- faststream/broker/utils.py | 2 +- faststream/cli/main.py | 4 ++-- faststream/confluent/client.py | 6 +++--- faststream/confluent/publisher/usecase.py | 2 +- faststream/confluent/schemas/partition.py | 2 +- faststream/confluent/subscriber/usecase.py | 2 +- faststream/confluent/testing.py | 2 +- faststream/kafka/publisher/usecase.py | 2 +- faststream/nats/testing.py | 2 +- faststream/rabbit/publisher/asyncapi.py | 6 +++--- faststream/rabbit/subscriber/asyncapi.py | 6 +++--- faststream/rabbit/testing.py | 2 +- faststream/redis/fastapi/fastapi.py | 2 +- faststream/redis/publisher/usecase.py | 6 +++--- faststream/redis/subscriber/usecase.py | 2 +- faststream/redis/testing.py | 4 ++-- faststream/testing/broker.py | 2 +- 24 files changed, 41 insertions(+), 41 deletions(-) diff --git a/faststream/_compat.py b/faststream/_compat.py index b823fb8035..a12c484d94 100644 --- a/faststream/_compat.py +++ b/faststream/_compat.py @@ -38,7 +38,7 @@ def is_test_env() -> bool: orjson = None try: - import ujson # type: ignore[no-redef] + import ujson except ImportError: ujson = None @@ -94,7 +94,7 @@ def raise_fastapi_validation_error(errors: List[Any], body: AnyDict) -> Never: from pydantic.annotated_handlers import ( GetJsonSchemaHandler as GetJsonSchemaHandler, ) - from pydantic_core.core_schema import ( # type: ignore[attr-defined] + from pydantic_core.core_schema import ( with_info_plain_validator_function as with_info_plain_validator_function, ) else: @@ -190,7 +190,7 @@ def with_info_plain_validator_function( # type: ignore[misc] from anyio import ExceptionGroup as ExceptionGroup # type: ignore[attr-defined] else: if sys.version_info < (3, 11): - from exceptiongroup import ( # type: ignore[assignment,no-redef] + from exceptiongroup import ( ExceptionGroup as ExceptionGroup, ) else: diff --git a/faststream/asyncapi/message.py b/faststream/asyncapi/message.py index e97c50f08f..b37415dedc 100644 --- a/faststream/asyncapi/message.py +++ b/faststream/asyncapi/message.py @@ -19,7 +19,7 @@ def parse_handler_params( body = get_model_schema( create_model( # type: ignore[call-overload] model.__name__, - **call.flat_params, # type: ignore[arg-type] + **call.flat_params, ), prefix=prefix, exclude=tuple(call.custom_fields.keys()), @@ -119,7 +119,7 @@ def get_model_schema( else: param_body[DEF_KEY] = defs - original_title = param.title if PYDANTIC_V2 else param.field_info.title # type: ignore[attr-defined] + original_title = param.title if PYDANTIC_V2 else param.field_info.title if original_title: use_original_model = True diff --git a/faststream/asyncapi/schema/info.py b/faststream/asyncapi/schema/info.py index cb49607f80..1e5a1a2d6f 100644 --- a/faststream/asyncapi/schema/info.py +++ b/faststream/asyncapi/schema/info.py @@ -78,7 +78,7 @@ def __get_pydantic_core_schema__( source : the source handler : the handler """ - return with_info_plain_validator_function(cls._validate) # type: ignore[no-any-return] + return with_info_plain_validator_function(cls._validate) class ContactDict(TypedDict, total=False): diff --git a/faststream/broker/fastapi/get_dependant.py b/faststream/broker/fastapi/get_dependant.py index 7c16cbdab2..ca85fce295 100644 --- a/faststream/broker/fastapi/get_dependant.py +++ b/faststream/broker/fastapi/get_dependant.py @@ -52,10 +52,10 @@ def _patch_fastapi_dependent(dependant: "Dependant") -> "Dependant": from faststream._compat import PydanticUndefined - params = dependant.query_params + dependant.body_params # type: ignore[attr-defined] + params = dependant.query_params + dependant.body_params for d in dependant.dependencies: - params.extend(d.query_params + d.body_params) # type: ignore[attr-defined] + params.extend(d.query_params + d.body_params) params_unique = {} for p in params: diff --git a/faststream/broker/fastapi/route.py b/faststream/broker/fastapi/route.py index e7ae9febbb..0c084ee061 100644 --- a/faststream/broker/fastapi/route.py +++ b/faststream/broker/fastapi/route.py @@ -114,12 +114,12 @@ def __init__( else: handler = call # type: ignore[assignment] - self.handler = broker.subscriber( # type: ignore[assignment,call-arg] + self.handler = broker.subscriber( # type: ignore[call-arg] *extra, dependencies=list(dependencies), **handle_kwargs, )( - handler, # type: ignore[arg-type] + handler, ) diff --git a/faststream/broker/fastapi/router.py b/faststream/broker/fastapi/router.py index afd070b3a5..c7a31a73a2 100644 --- a/faststream/broker/fastapi/router.py +++ b/faststream/broker/fastapi/router.py @@ -374,7 +374,7 @@ def after_startup( Callable[["AppType"], Awaitable[None]], ]: """Register a function to be executed after startup.""" - self._after_startup_hooks.append(to_async(func)) # type: ignore + self._after_startup_hooks.append(to_async(func)) return func @overload @@ -400,7 +400,7 @@ def on_broker_shutdown( Callable[["AppType"], Awaitable[None]], ]: """Register a function to be executed before broker stop.""" - self._on_shutdown_hooks.append(to_async(func)) # type: ignore + self._on_shutdown_hooks.append(to_async(func)) return func @abstractmethod diff --git a/faststream/broker/publisher/usecase.py b/faststream/broker/publisher/usecase.py index c401760a81..34a192670d 100644 --- a/faststream/broker/publisher/usecase.py +++ b/faststream/broker/publisher/usecase.py @@ -148,8 +148,8 @@ def get_payloads(self) -> List[Tuple["AnyDict", str]]: model=create_model("Fake"), response_model=create_model( # type: ignore[call-overload] "", - __config__=get_config_base(), # type: ignore[arg-type] - **params, # type: ignore[arg-type] + __config__=get_config_base(), + **params, ), params=params, ) diff --git a/faststream/broker/utils.py b/faststream/broker/utils.py index 568a1217f8..ceda2b6a5b 100644 --- a/faststream/broker/utils.py +++ b/faststream/broker/utils.py @@ -121,4 +121,4 @@ def resolve_custom_func( else: name = tuple(original_params.items())[1][0] - return partial(to_async(custom_func), **{name: default_func}) # type: ignore + return partial(to_async(custom_func), **{name: default_func}) diff --git a/faststream/cli/main.py b/faststream/cli/main.py index 5d416d26bf..8f2380c0cc 100644 --- a/faststream/cli/main.py +++ b/faststream/cli/main.py @@ -177,7 +177,7 @@ def _run( with suppress(ImportError): import uvloop - uvloop.install() # type: ignore[attr-defined] + uvloop.install() try: anyio.run( @@ -252,7 +252,7 @@ def publish( async def publish_message(broker: "BrokerUsecase[Any, Any]", extra: "AnyDict") -> Any: try: async with broker: - return await broker.publish(**extra) # type: ignore[union-attr] + return await broker.publish(**extra) except Exception as e: typer.echo(f"Error when broker was publishing: {e}") sys.exit(1) diff --git a/faststream/confluent/client.py b/faststream/confluent/client.py index 81168cbf54..0fb90122a9 100644 --- a/faststream/confluent/client.py +++ b/faststream/confluent/client.py @@ -100,7 +100,7 @@ def __init__( } ) - self.producer = Producer(self.config, logger=self.logger) # type: ignore[call-arg] + self.producer = Producer(self.config, logger=self.logger) async def stop(self) -> None: """Stop the Kafka producer and flush remaining messages.""" @@ -267,7 +267,7 @@ def __init__( } ) - self.consumer = Consumer(self.config, logger=self.logger) # type: ignore[call-arg] + self.consumer = Consumer(self.config, logger=self.logger) @property def topics_to_create(self) -> List[str]: @@ -336,7 +336,7 @@ async def getmany( ) -> Tuple[Message, ...]: """Consumes a batch of messages from Kafka and groups them by topic and partition.""" raw_messages: List[Optional[Message]] = await call_or_await( - self.consumer.consume, # type: ignore[arg-type] + self.consumer.consume, num_messages=max_records or 10, timeout=timeout, ) diff --git a/faststream/confluent/publisher/usecase.py b/faststream/confluent/publisher/usecase.py index b73b0de78c..7d5e07a304 100644 --- a/faststream/confluent/publisher/usecase.py +++ b/faststream/confluent/publisher/usecase.py @@ -140,7 +140,7 @@ async def publish( class BatchPublisher(LogicPublisher[Tuple[Message, ...]]): @override - async def publish( # type: ignore[override] + async def publish( self, message: Union["SendableMessage", Iterable["SendableMessage"]], *extra_messages: "SendableMessage", diff --git a/faststream/confluent/schemas/partition.py b/faststream/confluent/schemas/partition.py index e24a5608a3..1ec81e0355 100644 --- a/faststream/confluent/schemas/partition.py +++ b/faststream/confluent/schemas/partition.py @@ -36,4 +36,4 @@ def to_confluent(self) -> ConfluentPartition: kwargs["metadata"] = self.metadata if self.leader_epoch is not None: kwargs["leader_epoch"] = self.leader_epoch - return ConfluentPartition(**kwargs) # type: ignore[arg-type] + return ConfluentPartition(**kwargs) diff --git a/faststream/confluent/subscriber/usecase.py b/faststream/confluent/subscriber/usecase.py index f0f7c18a3a..9fd244ba8e 100644 --- a/faststream/confluent/subscriber/usecase.py +++ b/faststream/confluent/subscriber/usecase.py @@ -203,7 +203,7 @@ async def _consume(self) -> None: connected = True if msg is not None: - await self.consume(msg) # type: ignore[arg-type] + await self.consume(msg) @property def topic_names(self) -> List[str]: diff --git a/faststream/confluent/testing.py b/faststream/confluent/testing.py index 8af6903dec..a510fa9ea7 100644 --- a/faststream/confluent/testing.py +++ b/faststream/confluent/testing.py @@ -69,7 +69,7 @@ def create_publisher_fake_subscriber( def publisher_response_subscriber(msg: Any) -> None: pass - broker.setup_subscriber(sub) # type: ignore[arg-type] + broker.setup_subscriber(sub) return sub.calls[0].handler diff --git a/faststream/kafka/publisher/usecase.py b/faststream/kafka/publisher/usecase.py index 8fec375bba..a317986d35 100644 --- a/faststream/kafka/publisher/usecase.py +++ b/faststream/kafka/publisher/usecase.py @@ -195,7 +195,7 @@ async def publish( class BatchPublisher(LogicPublisher[Tuple["ConsumerRecord", ...]]): @override - async def publish( # type: ignore[override] + async def publish( self, message: Annotated[ Union["SendableMessage", Iterable["SendableMessage"]], diff --git a/faststream/nats/testing.py b/faststream/nats/testing.py index b998d26b43..cc14797af2 100644 --- a/faststream/nats/testing.py +++ b/faststream/nats/testing.py @@ -46,7 +46,7 @@ async def _fake_connect( # type: ignore[override] *args: Any, **kwargs: Any, ) -> AsyncMock: - broker.stream = AsyncMock() # type: ignore[assignment] + broker.stream = AsyncMock() broker._js_producer = broker._producer = FakeProducer(broker) # type: ignore[assignment] return AsyncMock() diff --git a/faststream/rabbit/publisher/asyncapi.py b/faststream/rabbit/publisher/asyncapi.py index 7e0c580cdd..415365481d 100644 --- a/faststream/rabbit/publisher/asyncapi.py +++ b/faststream/rabbit/publisher/asyncapi.py @@ -48,7 +48,7 @@ def get_schema(self) -> Dict[str, Channel]: return { self.name: Channel( - description=self.description, # type: ignore[attr-defined] + description=self.description, publish=Operation( bindings=OperationBinding( amqp=amqp.OperationBinding( @@ -76,7 +76,7 @@ def get_schema(self) -> Dict[str, Channel]: bindings=ChannelBinding( amqp=amqp.ChannelBinding( **{ - "is": "routingKey", # type: ignore + "is": "routingKey", "queue": amqp.Queue( name=self.queue.name, durable=self.queue.durable, @@ -90,7 +90,7 @@ def get_schema(self) -> Dict[str, Channel]: amqp.Exchange(type="default", vhost=self.virtual_host) if not self.exchange.name else amqp.Exchange( - type=self.exchange.type.value, # type: ignore + type=self.exchange.type.value, name=self.exchange.name, durable=self.exchange.durable, autoDelete=self.exchange.auto_delete, diff --git a/faststream/rabbit/subscriber/asyncapi.py b/faststream/rabbit/subscriber/asyncapi.py index 05313a6247..2ba7cabaa5 100644 --- a/faststream/rabbit/subscriber/asyncapi.py +++ b/faststream/rabbit/subscriber/asyncapi.py @@ -25,7 +25,7 @@ def get_schema(self) -> Dict[str, Channel]: return { self.name: Channel( - description=self.description, # type: ignore[attr-defined] + description=self.description, subscribe=Operation( bindings=OperationBinding( amqp=amqp.OperationBinding( @@ -45,7 +45,7 @@ def get_schema(self) -> Dict[str, Channel]: bindings=ChannelBinding( amqp=amqp.ChannelBinding( **{ - "is": "routingKey", # type: ignore + "is": "routingKey", "queue": amqp.Queue( name=self.queue.name, durable=self.queue.durable, @@ -59,7 +59,7 @@ def get_schema(self) -> Dict[str, Channel]: amqp.Exchange(type="default", vhost=self.virtual_host) if not self.exchange.name else amqp.Exchange( - type=self.exchange.type.value, # type: ignore + type=self.exchange.type.value, name=self.exchange.name, durable=self.exchange.durable, autoDelete=self.exchange.auto_delete, diff --git a/faststream/rabbit/testing.py b/faststream/rabbit/testing.py index 81df26f45f..a0cf2cd2e4 100644 --- a/faststream/rabbit/testing.py +++ b/faststream/rabbit/testing.py @@ -186,7 +186,7 @@ def __init__(self, broker: RabbitBroker) -> None: self.broker = broker @override - async def publish( # type: ignore[override] + async def publish( self, message: "AioPikaSendableMessage" = "", exchange: Union["RabbitExchange", str, None] = None, diff --git a/faststream/redis/fastapi/fastapi.py b/faststream/redis/fastapi/fastapi.py index 8521f0a433..ba18c339cc 100644 --- a/faststream/redis/fastapi/fastapi.py +++ b/faststream/redis/fastapi/fastapi.py @@ -668,7 +668,7 @@ def subscriber( # type: ignore[override] ) @override - def publisher( # type: ignore[override] + def publisher( self, channel: Annotated[ Union[str, PubSub, None], diff --git a/faststream/redis/publisher/usecase.py b/faststream/redis/publisher/usecase.py index 90cef8b883..bf578abf24 100644 --- a/faststream/redis/publisher/usecase.py +++ b/faststream/redis/publisher/usecase.py @@ -104,7 +104,7 @@ def add_prefix(self, prefix: str) -> None: self.channel = channel @override - async def publish( # type: ignore[override] + async def publish( self, message: Annotated[ "SendableMessage", @@ -231,7 +231,7 @@ def add_prefix(self, prefix: str) -> None: self.list = list_sub @override - async def publish( # type: ignore[override] + async def publish( self, message: Annotated[ "SendableMessage", @@ -405,7 +405,7 @@ def add_prefix(self, prefix: str) -> None: self.stream = stream_sub @override - async def publish( # type: ignore[override] + async def publish( self, message: Annotated[ "SendableMessage", diff --git a/faststream/redis/subscriber/usecase.py b/faststream/redis/subscriber/usecase.py index ca9719747a..dcfcd226f6 100644 --- a/faststream/redis/subscriber/usecase.py +++ b/faststream/redis/subscriber/usecase.py @@ -147,7 +147,7 @@ def _make_response_publisher( ) @override - async def start( # type: ignore[override] + async def start( self, *args: Any, ) -> None: diff --git a/faststream/redis/testing.py b/faststream/redis/testing.py index 2a625b80d6..def2ead166 100644 --- a/faststream/redis/testing.py +++ b/faststream/redis/testing.py @@ -56,7 +56,7 @@ async def _fake_connect( # type: ignore[override] *args: Any, **kwargs: Any, ) -> AsyncMock: - broker._producer = FakeProducer(broker) # type: ignore[assignment] + broker._producer = FakeProducer(broker) connection = MagicMock() pub_sub = AsyncMock() @@ -86,7 +86,7 @@ def __init__(self, broker: RedisBroker) -> None: self.broker = broker @override - async def publish( # type: ignore[override] + async def publish( self, message: "SendableMessage", *, diff --git a/faststream/testing/broker.py b/faststream/testing/broker.py index 813cd818aa..38478f8852 100644 --- a/faststream/testing/broker.py +++ b/faststream/testing/broker.py @@ -93,7 +93,7 @@ async def __aexit__(self, *args: Any) -> None: # TODO: remove useless middlewares filter middlewares: Tuple[BrokerMiddleware[Any], ...] = ( - CriticalLogMiddleware( # type: ignore[arg-type] + CriticalLogMiddleware( logger=self.broker.logger, log_level=self.broker._msg_log_level, ),