Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix msgspec pattern and optional annotated type #1606

Conversation

indrat
Copy link
Contributor

@indrat indrat commented Oct 6, 2023

Fixes #1605.

Also fixes an issue with the ordering/nesting of the Optional and Annotated types that I discovered while testing the Meta(pattern='...') constraint.

msgspec.Meta with pattern argument can only apply to a str type not a Optional[str] type as was previously being generated. So it's necessary to override the type hint behaviour when a field is Optional and annotated with a msgspec.Meta constraint.

indrat and others added 3 commits October 6, 2023 20:55
The Optional type should wrap the data_type annotated with msgspec.Meta
otherwise msgspec raises a TypeError like:

```
    TypeError: Can only set `pattern` on a str type - type `typing.Annotated[typing.Optional[str], msgspec.Meta(pattern='(^arn:([^:]*):([^:]*):([^:]*):(|\\*|[\\d]{12}):(.+)$)|^\\*$
')]` is invalid
```
@codecov
Copy link

codecov bot commented Oct 6, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (e9b6edf) 100.00% compared to head (221dae8) 100.00%.
Report is 736 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #1606     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        34     +23     
  Lines         1020      3731   +2711     
  Branches       201       874    +673     
===========================================
+ Hits          1020      3731   +2711     
Flag Coverage Δ
unittests 99.65% <99.60%> (?)

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

Files Coverage Δ
datamodel_code_generator/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/__main__.py 100.00% <100.00%> (ø)
datamodel_code_generator/arguments.py 100.00% <100.00%> (ø)
datamodel_code_generator/format.py 100.00% <100.00%> (ø)
datamodel_code_generator/http.py 100.00% <100.00%> (ø)
datamodel_code_generator/imports.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/base.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/dataclass.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/enum.py 100.00% <100.00%> (ø)
... and 24 more

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

@koxudaxi koxudaxi merged commit 23adaa5 into koxudaxi:master Oct 6, 2023
74 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.

msgspec output uses regex instead of pattern to Meta constraint
2 participants