Deprecate `scrapy.twisted_version` (#6512)

* Deprecate scrapy.twisted_version

* fix: typing

* remove typing

* raise default exception if attribute is not found

* remove redudant ()

* add tests

* rollback exception raised

* add filterwarnings again

* change order

* lint
This commit is contained in:
Laerte Pereira 2024-10-29 16:28:35 -03:00 committed by GitHub
parent 12b087b0f2
commit d2bdbad8c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 30 additions and 4 deletions

View File

@ -6,8 +6,6 @@ import pkgutil
import sys
import warnings
from twisted import version as _txv
# Declare top-level shortcuts
from scrapy.http import FormRequest, Request
from 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 warnings

View File

@ -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
)