Skip to content

Commit

Permalink
Formalize Python 3.9...3.13 support (#16)
Browse files Browse the repository at this point in the history
* Use `Optional` over `T | None` unions

* Add explicit support for 3.9...3.13 to setup.py

Add full range to test matrix: tests are fast here.

* Upgrade feedparser to 6.0.11: Python 3.13 support

kurtmckee/feedparser#330
  • Loading branch information
lukasschwab authored Feb 25, 2025
1 parent fb1dfe3 commit 966ba9f
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 49 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/python-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: python-test

on:
push:
branches: [ master ]
branches: [master]
pull_request:
workflow_dispatch:

Expand All @@ -13,19 +13,19 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest
make -B test
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Test with pytest
run: |
pip install pytest
make -B test
64 changes: 35 additions & 29 deletions jsonfeed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
""".. include:: ../README.md"""

import json
from typing import List

from typing import Optional


class ParseError(Exception):
Expand All @@ -20,19 +21,19 @@ class Feed:
def __init__(
self,
title: str,
home_page_url: str = None,
feed_url: str = None,
description: str = None,
user_comment: str = None,
next_url: str = None,
icon: str = None,
favicon: str = None,
home_page_url: Optional[str] = None,
feed_url: Optional[str] = None,
description: Optional[str] = None,
user_comment: Optional[str] = None,
next_url: Optional[str] = None,
icon: Optional[str] = None,
favicon: Optional[str] = None,
author=None, # 1.1 deprecated; use authors.
authors: List["Author"] = None,
authors: Optional[list["Author"]] = None,
expired: bool = False,
language: str = None,
hubs: List["Hub"] | None = None,
items: List["Item"] | None = None,
language: Optional[str] = None,
hubs: Optional[list["Hub"]] = None,
items: Optional[list["Item"]] = None,
):
assert title
self.title = title
Expand Down Expand Up @@ -121,7 +122,12 @@ def __repr__(self) -> str:


class Author:
def __init__(self, name: str = None, url: str = None, avatar: str = None):
def __init__(
self,
name: Optional[str] = None,
url: Optional[str] = None,
avatar: Optional[str] = None,
):
self.name = name
self.url = url
self.avatar = avatar
Expand Down Expand Up @@ -180,20 +186,20 @@ class Item:
def __init__(
self,
id,
url: str = None,
external_url: str = None,
title: str = None,
content_html: str = None,
content_text: str = None,
summary: str = None,
image: str = None,
banner_image: str = None,
date_published: str = None,
date_modified: str = None,
url: Optional[str] = None,
external_url: Optional[str] = None,
title: Optional[str] = None,
content_html: Optional[str] = None,
content_text: Optional[str] = None,
summary: Optional[str] = None,
image: Optional[str] = None,
banner_image: Optional[str] = None,
date_published: Optional[str] = None,
date_modified: Optional[str] = None,
author=None, # 1.1 deprecated; use authors.
authors: List[Author] = None,
tags: List[str] | None = None,
attachments: List["Attachment"] | None = None,
authors: Optional[list[Author]] = None,
tags: Optional[list[str]] = None,
attachments: Optional[list["Attachment"]] = None,
):
self.id = id
self.url = url
Expand Down Expand Up @@ -279,9 +285,9 @@ def __init__(
self,
url: str,
mime_type: str,
title: str = None,
size_in_bytes: int = None,
duration_in_seconds: int = None,
title: Optional[str] = None,
size_in_bytes: Optional[int] = None,
duration_in_seconds: Optional[int] = None,
):
self.url = url
self.mime_type = mime_type
Expand Down
3 changes: 1 addition & 2 deletions jsonfeed/converters/feedparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
```
"""

from typing import List
from jsonfeed import Feed, Author, Item, Attachment
from feedparser import FeedParserDict

Expand Down Expand Up @@ -70,7 +69,7 @@ def from_feedparser_entry(entry: FeedParserDict) -> Item:
)


def from_feedparser_links(links: List[FeedParserDict]) -> List[Attachment]:
def from_feedparser_links(links: list[FeedParserDict]) -> list[Attachment]:
return [from_feedparser_link(link) for link in links]


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
feedparser==6.0.2
feedparser==6.0.11

# Development dependencies
pytest>=6.2.2
Expand Down
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

version = "1.1.4"

with open("README.md", "r") as fh:
with open("README.md") as fh:
long_description = fh.read()

setup(
Expand All @@ -20,6 +20,12 @@
url="https://github.com/lukasschwab/jsonfeed",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
Expand Down

0 comments on commit 966ba9f

Please sign in to comment.