mirror of https://github.com/zulip/zulip.git
mypy: Reduce use of Any in zerver/lib/url_preview/ return types.
This commit is contained in:
parent
b972b083d9
commit
be856bad46
|
@ -1,9 +1,9 @@
|
|||
from typing import Optional, Any, Text
|
||||
from typing import Optional, Text, Dict
|
||||
from pyoembed import oEmbed, PyOembedException
|
||||
|
||||
|
||||
def get_oembed_data(url, maxwidth=640, maxheight=480):
|
||||
# type: (Text, Optional[int], Optional[int]) -> Any
|
||||
# type: (Text, Optional[int], Optional[int]) -> Optional[Dict]
|
||||
try:
|
||||
data = oEmbed(url, maxwidth=maxwidth, maxheight=maxheight)
|
||||
except PyOembedException:
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
from typing import Any, Dict
|
||||
from typing import Dict, Optional, Text
|
||||
from zerver.lib.url_preview.parsers.base import BaseParser
|
||||
|
||||
|
||||
class GenericParser(BaseParser):
|
||||
def extract_data(self):
|
||||
# type: () -> Dict
|
||||
# type: () -> Dict[str, Optional[Text]]
|
||||
return {
|
||||
'title': self._get_title(),
|
||||
'description': self._get_description(),
|
||||
'image': self._get_image()}
|
||||
|
||||
def _get_title(self):
|
||||
# type: () -> Any
|
||||
# type: () -> Optional[Text]
|
||||
soup = self._soup
|
||||
if (soup.title and soup.title.text != ''):
|
||||
return soup.title.text
|
||||
|
@ -20,7 +20,7 @@ class GenericParser(BaseParser):
|
|||
return None
|
||||
|
||||
def _get_description(self):
|
||||
# type: () -> Any
|
||||
# type: () -> Optional[Text]
|
||||
soup = self._soup
|
||||
meta_description = soup.find('meta', attrs={'name': 'description'})
|
||||
if (meta_description and meta_description['content'] != ''):
|
||||
|
@ -36,7 +36,7 @@ class GenericParser(BaseParser):
|
|||
return None
|
||||
|
||||
def _get_image(self):
|
||||
# type: () -> Any
|
||||
# type: () -> Optional[Text]
|
||||
"""
|
||||
Finding a first image after the h1 header.
|
||||
Presumably it will be the main image.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import re
|
||||
import logging
|
||||
import traceback
|
||||
from typing import Any, Optional, Text
|
||||
from typing import Any, Optional, Text, Dict
|
||||
from typing.re import Match
|
||||
import requests
|
||||
from zerver.lib.cache import cache_with_key, get_cache_with_key
|
||||
|
@ -32,7 +32,7 @@ def cache_key_func(url):
|
|||
|
||||
@cache_with_key(cache_key_func, cache_name=CACHE_NAME, with_statsd_key="urlpreview_data")
|
||||
def get_link_embed_data(url, maxwidth=640, maxheight=480):
|
||||
# type: (Text, Optional[int], Optional[int]) -> Any
|
||||
# type: (Text, Optional[int], Optional[int]) -> Optional[Dict]
|
||||
if not is_link(url):
|
||||
return None
|
||||
# Fetch information from URL.
|
||||
|
|
Loading…
Reference in New Issue