Skip to content

Commit

Permalink
Disambiguate generic list type hints (#109)
Browse files Browse the repository at this point in the history
* Disambiguate generic list types

Also updates string annotations in constructor arguments.

Imports `annotations` from `__future__`, which allows referring to
class types before they're defined.

Verification: searched for all instances of `: list`; there aren't any
left in arxiv.py. Generated docs look good.

* Increment version for patch
  • Loading branch information
lukasschwab authored Apr 17, 2023
1 parent e5ba7f8 commit 6f3e908
Show file tree
Hide file tree
Showing 3 changed files with 1,945 additions and 1,941 deletions.
20 changes: 11 additions & 9 deletions arxiv/arxiv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""".. include:: ../README.md"""
from __future__ import annotations

import logging
import time
import feedparser
Expand Down Expand Up @@ -35,7 +37,7 @@ class Result(object):
"""When the result was originally published."""
title: str
"""The title of the result."""
authors: list
authors: List[Author]
"""The result's authors."""
summary: str
"""The result abstract."""
Expand All @@ -55,7 +57,7 @@ class Result(object):
All of the result's categories. See [arXiv: Category
Taxonomy](https://arxiv.org/category_taxonomy).
"""
links: list
links: List[Link]
"""Up to three URLs associated with this result."""
pdf_url: str
"""The URL of a PDF version of this result if present among links."""
Expand All @@ -71,14 +73,14 @@ def __init__(
updated: datetime = _DEFAULT_TIME,
published: datetime = _DEFAULT_TIME,
title: str = "",
authors: List['Result.Author'] = [],
authors: List[Author] = [],
summary: str = "",
comment: str = "",
journal_ref: str = "",
doi: str = "",
primary_category: str = "",
categories: List[str] = [],
links: List['Result.Link'] = [],
links: List[Link] = [],
_raw: feedparser.FeedParserDict = None,
):
"""
Expand All @@ -104,7 +106,7 @@ def __init__(
# Debugging
self._raw = _raw

def _from_feed_entry(entry: feedparser.FeedParserDict) -> 'Result':
def _from_feed_entry(entry: feedparser.FeedParserDict) -> Result:
"""
Converts a feedparser entry for an arXiv search result feed into a
Result object.
Expand Down Expand Up @@ -221,7 +223,7 @@ def download_source(self, dirpath: str = './', filename: str = '') -> str:
written_path, _ = urlretrieve(source_url, path)
return written_path

def _get_pdf_url(links: list) -> str:
def _get_pdf_url(links: List[Link]) -> str:
"""
Finds the PDF link among a result's links and returns its URL.
Expand Down Expand Up @@ -266,7 +268,7 @@ def __init__(self, name: str):

def _from_feed_author(
feed_author: feedparser.FeedParserDict
) -> 'Result.Author':
) -> Result.Author:
"""
Constructs an `Author` with the name specified in an author object
from a feed entry.
Expand Down Expand Up @@ -320,7 +322,7 @@ def __init__(

def _from_feed_link(
feed_link: feedparser.FeedParserDict
) -> 'Result.Link':
) -> Result.Link:
"""
Constructs a `Link` with link metadata specified in a link object
from a feed entry.
Expand Down Expand Up @@ -416,7 +418,7 @@ class Search(object):
See [the arXiv API User's Manual: Details of Query
Construction](https://arxiv.org/help/api/user-manual#query_details).
"""
id_list: list
id_list: List[str]
"""
A list of arXiv article IDs to which to limit the search.
Expand Down
Loading

0 comments on commit 6f3e908

Please sign in to comment.