Skip to content

Another attempt for stdin#616

Merged
niknetniko merged 2 commits intofiles-featuresfrom
feature/stdin-yet-again
Feb 28, 2026
Merged

Another attempt for stdin#616
niknetniko merged 2 commits intofiles-featuresfrom
feature/stdin-yet-again

Conversation

@niknetniko
Copy link
Member


For those interested, this is the actual cause, from the commit message:

Cattrs works by passing the value it is structuring into the default constructor of the target type, so it supports Python's coercions. In this specific case, consider the previous version of TextData:

class TextData:
  data: str
  type: "text" | "file"

When a test suite containing {'type': 'text', 'data': 500} is structured, cattrs will attempt to structure data by doing str(500). This is legal, so cattrs happily accepts it.

The new definition, however, is as follows:

class TextData:
  content: ContentPath | str
  path: str | None = None

When the decorator runs and returns the value from data as an int, cattrs will take over, trying to structure it into ContentPath | str. TESTed has a custom union structuring function to allow structuring into any union. However, it does no data coercion: it requires exact types, which is why the code failed and the old test suite no longer works.

…ges"

This reverts commit 16ce3cf, reversing
changes made to 3329a84.
Cattrs works by passing the value it is structuring into the default
constructor of the target type, so it supports Python's coercions.

In this case, consider the previous version of TextData:

class TextData:
  data: str
  type: "text" | "file"

When a test suite containing {'type': 'text', 'data': 500} is
structured, cattrs will attempt to structute `data` by doing `str(500)`.
This is legal, so cattrs happily accepts it.

The new definition, however, is as follows:

class TextData:
  content: ContentPath | str
  path: str | None = None

When the decorator runs and returns the value from data as an int,
cattrs will take over, trying to structure it into `ContentPath | str`.
TESTed has a custom union structuring function to allow structuring
into any union. One thing it does not do, however, is the data coercion.

The union structuring requires exact types, which is why the code failed
and the old test suite no longer works.

To fix this, we now explicitly coerce the legacy data to a string inside
the fallback converter before it reaches the strict union hook.
@niknetniko niknetniko self-assigned this Feb 19, 2026
@niknetniko niknetniko marked this pull request as ready for review February 26, 2026 17:01
@niknetniko niknetniko requested a review from chvp February 26, 2026 17:01
@niknetniko niknetniko changed the base branch from master to files-features February 28, 2026 14:55
@niknetniko
Copy link
Member Author

Merging into a "files" branch so we can have all file-related stuff together before merging to master.

@niknetniko niknetniko merged commit 1b8f351 into files-features Feb 28, 2026
14 of 15 checks passed
@niknetniko niknetniko deleted the feature/stdin-yet-again branch February 28, 2026 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants