Skip to content

Conversation

dapper91
Copy link
Owner

eltoder and others added 5 commits July 2, 2025 01:00
There are 2 issues with the annotations:

1. Function types are contravariant rather than covariant in their
   argument types. This means that `Callable[[BaseXmlModel], Any]` is a
   subtype rather than a supertype of `Callable[[MyModel], Any]` and so
   using `Callable[[BaseXmlModel], Any]` as a lower bound of TypeVars
   doesn't work. Since Python doesn't support upper bounds on TypeVars,
   the solution is to push the TypeVar inside. To see the issue run mypy
   on the example from the documentation[1]. Currently, you get these
   errors:

```
t.py:13: error: Value of type variable "ValidatorFuncT" of function cannot be "Callable[[type[Plot], XmlElementReader, str], list[float]]"  [type-var]
t.py:21: error: Value of type variable "SerializerFuncT" of function cannot be "Callable[[Plot, XmlElementWriter, list[float], str], None]"  [type-var]
```

   This PR resolves these (however, validate_space_separated_list needs
   to be decorated with @classmethod).

2. A recent commit[2] has a typo where ValidatorFuncT was bound by
   SerializerFunc instead of ValidatorFunc.

[1] https://pydantic-xml.readthedocs.io/en/latest/pages/misc.html#custom-xml-serialization
[2] ec4b547
Fix type annotations for xml_field_validator/serializer
@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.31%. Comparing base (526259e) to head (3fecbed).
Report is 47 commits behind head on master.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #280   +/-   ##
=======================================
  Coverage   92.30%   92.31%           
=======================================
  Files          30       30           
  Lines        1728     1730    +2     
=======================================
+ Hits         1595     1597    +2     
  Misses        133      133           
Flag Coverage Δ
unittests 92.31% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dapper91 dapper91 merged commit 7c7590a into master Jul 13, 2025
6 checks passed
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.

3 participants