Skip to content

Conversation

@radoering
Copy link
Member

@radoering radoering commented Dec 31, 2025

Related-to: python-poetry/poetry-plugin-export#336
Related-to: python-poetry/poetry#10356
Related-to: python-poetry/poetry#10646

  • Added tests for changed code.
  • Updated documentation for changed code.

Summary by Sourcery

Add optional distribution file size and upload timestamp metadata to links and package files.

New Features:

  • Expose optional size and upload_time fields on package link objects, including parsed datetime access for upload_time.
  • Allow Package.files entries to carry optional url, size, and upload_time metadata.

Tests:

  • Add unit tests covering default and explicit size and upload_time handling on Link, including ISO 8601 timestamp parsing.

@sourcery-ai
Copy link

sourcery-ai bot commented Dec 31, 2025

Reviewer's Guide

Adds optional size and upload_time metadata to Link objects and Package.files entries, wiring through initialization, typed dict structure, and providing parsed datetime accessors plus tests for the new behavior.

Class diagram for updated Link and PackageFile structures

classDiagram
    class Link {
        -url str
        -_metadata str|bool|dict~str,str~|None
        -_yanked str|bool
        -_size int|None
        -_upload_time str|None
        +__init__(url str, requires_python str|None, yanked str|bool, hashes Mapping~str,str~|None, metadata str|bool|dict~str,str~|None, size int|None, upload_time str|None) void
        +__str__() str
        +yanked() bool
        +yanked_reason() str
        +size() int|None
        +upload_time_isoformat() str|None
        +upload_time() datetime|None
    }

    class _PackageFile {
        +file str
        +hash str
    }

    class PackageFile {
        +file str
        +hash str
        +url str
        +size int
        +upload_time str
    }

    class Package {
        +files list~PackageFile~
    }

    PackageFile --|> _PackageFile : extends
    Package "1" --> "*" PackageFile : uses as files
Loading

File-Level Changes

Change Details Files
Extend Link to carry optional file size and upload time and expose parsed upload_time as datetime.
  • Add size and upload_time parameters to Link.init with internal storage on the instance
  • Document the new size and upload_time parameters in Link docstring
  • Add cached_property accessors for size, upload_time_isoformat, and upload_time with ISO 8601 parsing and graceful failure for invalid formats
src/poetry/core/packages/utils/link.py
Extend PackageFile metadata structure to optionally include URL, file size, and upload time.
  • Introduce internal _PackageFile TypedDict for required fields file and hash
  • Define PackageFile as a non-total TypedDict extending _PackageFile, adding optional url, size, and upload_time keys
  • Include comments describing future use of PEP 655 and PEP 705 when older Python versions are dropped
src/poetry/core/packages/package.py
Add tests covering new size and upload_time behavior on Link, including default values and parsing.
  • Test that Link.size defaults to None and can be set explicitly
  • Test that Link.upload_time defaults to None when not provided
  • Parametrized tests to verify correct parsing of various ISO 8601 upload_time formats, including Z suffix and fractional seconds
tests/packages/utils/test_utils_link.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • The test_package_link_size_default_None test name is misleading since it sets size=1234 and asserts that value; consider renaming it (e.g. test_package_link_size_explicit_value) to better reflect its purpose.
  • In Link.upload_time, using self._upload_time.replace("Z", "+00:00") will replace all Z characters, not just a trailing UTC designator; it would be safer to normalize only a terminal Z (e.g. with endswith("Z")) before calling datetime.fromisoformat.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `test_package_link_size_default_None` test name is misleading since it sets `size=1234` and asserts that value; consider renaming it (e.g. `test_package_link_size_explicit_value`) to better reflect its purpose.
- In `Link.upload_time`, using `self._upload_time.replace("Z", "+00:00")` will replace all `Z` characters, not just a trailing UTC designator; it would be safer to normalize only a terminal `Z` (e.g. with `endswith("Z")`) before calling `datetime.fromisoformat`.

## Individual Comments

### Comment 1
<location> `tests/packages/utils/test_utils_link.py:3-9` </location>
<code_context>
+    assert link.upload_time is None
+
+
[email protected](
+    ("upload_time", "expected"),
+    [
+        ("2023-06-15T08:30:45Z", datetime(2023, 6, 15, 8, 30, 45, tzinfo=timezone.utc)),
+        (
+            "2022-12-31T23:59:59+00:00",
+            datetime(2022, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
+        ),
+        (
+            "2023-06-15T08:30:45.123456Z",
+            datetime(2023, 6, 15, 8, 30, 45, 123456, tzinfo=timezone.utc),
+        ),
+    ],
+)
+def test_package_link_upload_time(upload_time: str, expected: datetime) -> None:
+    link = Link("https://example.org", upload_time=upload_time)
+
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding tests for invalid and offsetted `upload_time` values

The current parametrized test nicely covers several valid ISO 8601 formats. To strengthen it, please also add cases for (1) an invalid ISO string (e.g. "not-a-timestamp") to assert `link.upload_time` is `None`, and (2) a timestamp with a non-zero offset (e.g. `"2023-06-15T10:30:45+02:00"`) so offset handling and behavior on older Python versions are exercised and guarded against regressions.

```suggestion
import uuid

from datetime import datetime
from datetime import timezone
from hashlib import sha256

import pytest


@pytest.mark.parametrize(
    ("upload_time", "expected"),
    [
        (
            "2023-06-15T08:30:45Z",
            datetime(2023, 6, 15, 8, 30, 45, tzinfo=timezone.utc),
        ),
        (
            "2022-12-31T23:59:59+00:00",
            datetime(2022, 12, 31, 23, 59, 59, tzinfo=timezone.utc),
        ),
        (
            "2023-06-15T08:30:45.123456Z",
            datetime(2023, 6, 15, 8, 30, 45, 123456, tzinfo=timezone.utc),
        ),
        (
            "2023-06-15T10:30:45+02:00",
            datetime(2023, 6, 15, 8, 30, 45, tzinfo=timezone.utc),
        ),
        ("not-a-timestamp", None),
    ],
)
def test_package_link_upload_time(upload_time: str, expected: object) -> None:
    link = Link("https://example.org", upload_time=upload_time)

    assert link.upload_time == expected

    assert link.yanked == expected_yanked
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@radoering radoering force-pushed the file-url-size-upload-time branch from d98dadd to 4f0b458 Compare December 31, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant