Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mypy: Correct typing.re imports to typing.
Anders Kaseorg986490798593
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex e93194b5792..92720517d3c 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -11,8 +11,20 @@ import urllib.parsefrom collections import defaultdict, dequefrom dataclasses import dataclassfrom io import StringIO-from typing import Any, Callable, Dict, Generic, List, Optional, Set, Tuple, TypeVar, Union-from typing.re import Match, Pattern+from typing import (+ Any,+ Callable,+ Dict,+ Generic,+ List,+ Match,+ Optional,+ Pattern,+ Set,+ Tuple,+ TypeVar,+ Union,+)from urllib.parse import urlencode, urlsplitfrom xml.etree import ElementTree as etreefrom xml.etree.ElementTree import Element, SubElement@@ -111,14 +123,14 @@ ElementStringNone = Union[Element, Optional[str]]EMOJI_REGEX = r"(?P<syntax>:[\w\-\+]+:)"-def verbose_compile(pattern: str) -> Any:+def verbose_compile(pattern: str) -> Pattern[str]:return re.compile(f"^(.*?){pattern}(.*?)$",re.DOTALL | re.UNICODE | re.VERBOSE,)-def normal_compile(pattern: str) -> Any:+def normal_compile(pattern: str) -> Pattern[str]:return re.compile(fr"^(.*?){pattern}(.*)$",re.DOTALL | re.UNICODE,@@ -134,7 +146,7 @@ STREAM_LINK_REGEX = r"""@one_time-def get_compiled_stream_link_regex() -> Pattern:+def get_compiled_stream_link_regex() -> Pattern[str]:return verbose_compile(STREAM_LINK_REGEX)@@ -149,14 +161,14 @@ STREAM_TOPIC_LINK_REGEX = r"""@one_time-def get_compiled_stream_topic_link_regex() -> Pattern:+def get_compiled_stream_topic_link_regex() -> Pattern[str]:return verbose_compile(STREAM_TOPIC_LINK_REGEX)-LINK_REGEX: Pattern = None+LINK_REGEX: Optional[Pattern[str]] = None-def get_web_link_regex() -> str:+def get_web_link_regex() -> Pattern[str]:# We create this one time, but not at startup. So the# first message rendered in any process will have some# extra costs. It's roughly 75ms to run this code, so@@ -1465,7 +1477,7 @@ class UnicodeEmoji(markdown.inlinepatterns.Pattern):class Emoji(markdown.inlinepatterns.Pattern):- def handleMatch(self, match: Match[str]) -> Optional[Element]:+ def handleMatch(self, match: Match[str]) -> Optional[Union[str, Element]]:orig_syntax = match.group("syntax")name = orig_syntax[1:-1]@@ -1588,7 +1600,7 @@ def url_to_a(class CompiledPattern(markdown.inlinepatterns.Pattern):- def __init__(self, compiled_re: Pattern, md: markdown.Markdown) -> None:+ def __init__(self, compiled_re: Pattern[str], md: markdown.Markdown) -> None:# This is similar to the superclass's small __init__ function,# but we skip the compilation step and let the caller give us# a compiled regex.@@ -1857,7 +1869,7 @@ class UserGroupMentionPattern(markdown.inlinepatterns.Pattern):class StreamPattern(CompiledPattern):- def find_stream_by_name(self, name: Match[str]) -> Optional[Dict[str, Any]]:+ def find_stream_by_name(self, name: str) -> Optional[Dict[str, Any]]:db_data = self.md.zulip_db_dataif db_data is None:return None@@ -1888,7 +1900,7 @@ class StreamPattern(CompiledPattern):class StreamTopicPattern(CompiledPattern):- def find_stream_by_name(self, name: Match[str]) -> Optional[Dict[str, Any]]:+ def find_stream_by_name(self, name: str) -> Optional[Dict[str, Any]]:db_data = self.md.zulip_db_dataif db_data is None:return Nonediff --git a/zerver/lib/markdown/help_emoticon_translations_table.py b/zerver/lib/markdown/help_emoticon_translations_table.pyindex b172259653f..834f3a0c6bd 100644--- a/zerver/lib/markdown/help_emoticon_translations_table.py+++ b/zerver/lib/markdown/help_emoticon_translations_table.py@@ -1,6 +1,5 @@import re-from typing import Any, List-from typing.re import Match+from typing import Any, List, Matchfrom markdown import Markdownfrom markdown.extensions import Extensiondiff --git a/zerver/lib/markdown/help_relative_links.py b/zerver/lib/markdown/help_relative_links.pyindex 968e1032c7a..18362f41c16 100644--- a/zerver/lib/markdown/help_relative_links.py+++ b/zerver/lib/markdown/help_relative_links.py@@ -1,6 +1,5 @@import re-from typing import Any, List, Optional-from typing.re import Match+from typing import Any, List, Match, Optionalfrom markdown import Markdownfrom markdown.extensions import Extensiondiff --git a/zerver/lib/markdown/help_settings_links.py b/zerver/lib/markdown/help_settings_links.pyindex fd4009f8516..82958bbb0e6 100644--- a/zerver/lib/markdown/help_settings_links.py+++ b/zerver/lib/markdown/help_settings_links.py@@ -1,6 +1,5 @@import re-from typing import Any, List, Optional-from typing.re import Match+from typing import Any, List, Match, Optionalfrom markdown import Markdownfrom markdown.extensions import Extensiondiff --git a/zerver/lib/url_preview/preview.py b/zerver/lib/url_preview/preview.pyindex bcfcc5ca287..481c7f0d154 100644--- a/zerver/lib/url_preview/preview.py+++ b/zerver/lib/url_preview/preview.py@@ -1,6 +1,5 @@import re-from typing import Any, Callable, Dict, Optional-from typing.re import Match+from typing import Any, Callable, Dict, Match, Optionalimport magicimport requests@@ -37,7 +36,7 @@ HEADERS = {"User-Agent": ZULIP_URL_PREVIEW_USER_AGENT}TIMEOUT = 15-def is_link(url: str) -> Match[str]:+def is_link(url: str) -> Optional[Match[str]]:return link_regex.match(smart_text(url))