Skip to content

Commit 9aabcf7

Browse files
committed
squashme: conditional typing imports, suggestions
1 parent 5fa96f9 commit 9aabcf7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

sopel/modules/url.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@
1313
from ipaddress import ip_address
1414
import logging
1515
import re
16-
from typing import Generator, List, Optional, Tuple
16+
from typing import TYPE_CHECKING
1717
from urllib.parse import urlparse
1818

1919
import dns.resolver
2020
import requests
2121
from urllib3.exceptions import LocationValueError # type: ignore[import]
2222

2323
from sopel import plugin, tools
24-
from sopel.bot import Sopel, SopelWrapper
25-
from sopel.config import Config, types
24+
from sopel.config import types
2625
from sopel.tools import web
27-
from sopel.trigger import Trigger
2826

27+
if TYPE_CHECKING:
28+
from typing import Generator, List, Optional, Tuple
29+
30+
from sopel.bot import Sopel, SopelWrapper
31+
from sopel.config import Config
32+
from sopel.trigger import Trigger
2933

3034
LOGGER = logging.getLogger(__name__)
3135
USER_AGENT = (
@@ -320,6 +324,11 @@ def process_urls(
320324
"""
321325
For each URL in the list, ensure it should be titled, and do so.
322326
327+
:param bot: Sopel instance
328+
:param trigger: The trigger object for this event
329+
:param urls: The URLs detected in the triggering message
330+
:param requested: Whether the title was explicitly requested (vs automatic)
331+
323332
See if it's handled by another plugin. If not, find where it redirects to,
324333
if anywhere. If that redirected URL should be handled by another plugin,
325334
dispatch the callback for it. Return a list of
@@ -329,11 +338,6 @@ def process_urls(
329338
330339
For titles explicitly requested by the user, exclusion_char and excludes
331340
are skipped.
332-
333-
:param bot: Sopel instance
334-
:param trigger: The trigger object for this event
335-
:param urls: The URLs detected in the triggering message
336-
:param requested: Whether the title was explicitly requested (vs automatic)
337341
"""
338342
shorten_url_length = bot.config.url.shorten_url_length
339343
for url in urls:
@@ -406,9 +410,9 @@ def check_callbacks(bot: SopelWrapper, url: str, use_excludes: bool = True) -> b
406410
407411
"""
408412
# Check if it matches the exclusion list first
409-
excluded = False
410-
if use_excludes:
411-
excluded = any(regex.search(url) for regex in bot.memory["url_exclude"])
413+
excluded = use_excludes and any(
414+
regex.search(url) for regex in bot.memory["url_exclude"]
415+
)
412416
return (
413417
excluded or
414418
any(bot.search_url_callbacks(url)) or

0 commit comments

Comments
 (0)