Scrapy, a fast high-level web crawling & scraping framework for Python.
Deprecate `scrapy.twisted_version` (#6512)
Laerte Pereirad2bdbad8c8cc
diff --git a/scrapy/__init__.py b/scrapy/__init__.pyindex 1c1a5c2cc..921296502 100644--- a/scrapy/__init__.py+++ b/scrapy/__init__.py@@ -6,8 +6,6 @@ import pkgutilimport sysimport warnings-from twisted import version as _txv-# Declare top-level shortcutsfrom scrapy.http import FormRequest, Requestfrom scrapy.item import Field, Item@@ -17,7 +15,6 @@ from scrapy.spiders import Spider__all__ = ["__version__","version_info",- "twisted_version","Spider","Request","FormRequest",@@ -30,7 +27,23 @@ __all__ = [# Scrapy and Twisted versions__version__ = (pkgutil.get_data(__package__, "VERSION") or b"").decode("ascii").strip()version_info = tuple(int(v) if v.isdigit() else v for v in __version__.split("."))-twisted_version = (_txv.major, _txv.minor, _txv.micro)+++def __getattr__(name: str):+ if name == "twisted_version":+ import warnings++ from twisted import version as _txv++ from scrapy.exceptions import ScrapyDeprecationWarning++ warnings.warn(+ "The scrapy.twisted_version attribute is deprecated, use twisted.version instead",+ ScrapyDeprecationWarning,+ )+ return _txv.major, _txv.minor, _txv.micro++ raise AttributeError# Ignore noisy twisted deprecation warningsdiff --git a/tests/test_scrapy__getattr__.py b/tests/test_scrapy__getattr__.pynew file mode 100644index 000000000..979c42267--- /dev/null+++ b/tests/test_scrapy__getattr__.py@@ -0,0 +1,13 @@+import warnings+++def test_deprecated_twisted_version():+ with warnings.catch_warnings(record=True) as warns:+ from scrapy import twisted_version++ assert twisted_version is not None+ assert isinstance(twisted_version, tuple)+ assert (+ "The scrapy.twisted_version attribute is deprecated, use twisted.version instead"+ in warns[0].message.args+ )