Skip to content

Commit

Permalink
Remove has_cache_support
Browse files Browse the repository at this point in the history
  • Loading branch information
lampssy committed Jun 30, 2023
1 parent 655cb96 commit 36d8705
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 28 deletions.
14 changes: 0 additions & 14 deletions scrapy_poet/page_input_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,13 @@
ResponseUrl,
)
from web_poet.pages import is_injectable
from web_poet.serialization import serialize_leaf

from scrapy_poet.downloader import create_scrapy_downloader
from scrapy_poet.injection_errors import (
MalformedProvidedClassesError,
ProviderDependencyDeadlockError,
)

from .utils import get_registered_anotations


class PageObjectInputProvider:
"""
Expand Down Expand Up @@ -122,17 +119,6 @@ def is_provided(self, type_: Callable) -> bool:
f"{self!r}. Expected either 'set' or 'callable'"
)

@property
def has_cache_support(self):
registered_annotations = get_registered_anotations(serialize_leaf)
has_cache_support = False
for annotation in registered_annotations:
if self.is_provided(annotation):
has_cache_support = True
break

return has_cache_support

# FIXME: Can't import the Injector as class annotation due to circular dep.
def __init__(self, injector):
"""Initializes the provider. Invoked only at spider start up."""
Expand Down
15 changes: 1 addition & 14 deletions scrapy_poet/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from functools import lru_cache
from typing import Any, Callable, List, Type
from typing import Type
from warnings import warn

from packaging.version import Version
Expand Down Expand Up @@ -76,16 +76,3 @@ def create_registry_instance(cls: Type, crawler: Crawler):
@lru_cache()
def is_min_scrapy_version(version: str) -> bool:
return Version(SCRAPY_VERSION) >= Version(version)


def get_registered_anotations(generic_func: Callable) -> List[type]:
"""Get argument annotations from all registered functions for a given generic function"""
registered_funcs: List[Callable] = list(generic_func.registry.values()) # type: ignore[attr-defined]
registered_annotations = []
for func in registered_funcs:
# get all parameter annotations, except from the return value
# `inspect.get_annotations()` could be a better option but it's not compatible with python<3.10
annotations = list(func.__annotations__.values())[:-1]
registered_annotations += annotations

return [t for t in registered_annotations if t != Any]

0 comments on commit 36d8705

Please sign in to comment.