From 416bd919badd8135327c24ab19137f6b7c91ad7b Mon Sep 17 00:00:00 2001 From: Karim shoair Date: Wed, 26 Mar 2025 02:49:02 +0200 Subject: [PATCH] fix: backward-compatibility with the new import logic --- scrapling/defaults.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scrapling/defaults.py b/scrapling/defaults.py index 4098f76..903cf6f 100644 --- a/scrapling/defaults.py +++ b/scrapling/defaults.py @@ -1,19 +1,25 @@ -# If you are going to use Fetchers with the default settings, import them from this file instead for a cleaner looking code +# Left this file for backward-compatibility before 0.2.99 +from scrapling.core.utils import log + # A lightweight approach to create lazy loader for each import for backward compatibility # This will reduces initial memory footprint significantly (only loads what's used) def __getattr__(name): if name == 'Fetcher': from scrapling.fetchers import Fetcher as cls - return cls() + log.warning('This import is deprecated now and it will be removed with v0.3. Use `from scrapling.fetchers import Fetcher` instead') + return cls elif name == 'AsyncFetcher': from scrapling.fetchers import AsyncFetcher as cls - return cls() + log.warning('This import is deprecated now and it will be removed with v0.3. Use `from scrapling.fetchers import AsyncFetcher` instead') + return cls elif name == 'StealthyFetcher': from scrapling.fetchers import StealthyFetcher as cls - return cls() + log.warning('This import is deprecated now and it will be removed with v0.3. Use `from scrapling.fetchers import StealthyFetcher` instead') + return cls elif name == 'PlayWrightFetcher': from scrapling.fetchers import PlayWrightFetcher as cls - return cls() + log.warning('This import is deprecated now and it will be removed with v0.3. Use `from scrapling.fetchers import PlayWrightFetcher` instead') + return cls else: raise AttributeError(f"module 'scrapling' has no attribute '{name}'")