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

Add support for enhanced builtin instantiation #375

Conversation

rpmcginty
Copy link
Contributor

What's in this change?

  • Adding improved instantiation logic for str, int, float in dataclass decoder.
  • Fixing bugs in test code

Why do we need improved instantiation logic for these builtins?

There are a few reasons why instantiating using the intended type when they are one of the three is beneficial.

  1. Support for custom str classes is covered. Previously this was not supported as str is treated special in the decode logic. This is further documented here: Add support for str subclasses  #348
  2. Improved support for conversion from input X -> int|float. Previously, values that represented numeric values (either stringified numeric values or Decimal objects) were not converted properly into the intended field type. So a dataclass field specified as an int would not decode "42" or decimal.Decimal("42") as 42. This differs from marshmallow decode behavior which properly converts to the integer value.

Testing

Added tests to demonstrate new usage

Note that this will fail tests until this PR is merged: #374

@george-zubrienko
Copy link
Collaborator

@rpmcginty could you please sync your branch so CI runs and then we can merge :)

@george-zubrienko george-zubrienko self-assigned this Jun 7, 2023
@rpmcginty
Copy link
Contributor Author

@george-zubrienko done!

@george-zubrienko george-zubrienko merged commit e5cf202 into lidatong:master Jun 14, 2023
5 checks passed
@george-zubrienko
Copy link
Collaborator

george-zubrienko commented Jun 14, 2023

@george-zubrienko done!

Thank you! If there is anything else pending merge, just sync the PR and ping me in comments :)

bruxisma pushed a commit to ixm-one/pytest-cmake-presets that referenced this pull request Jul 20, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [dataclasses-json](https://togithub.com/lidatong/dataclasses-json) |
`0.5.8` -> `0.5.12` |
[![age](https://developer.mend.io/api/mc/badges/age/pypi/dataclasses-json/0.5.12?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/pypi/dataclasses-json/0.5.12?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/pypi/dataclasses-json/0.5.8/0.5.12?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/dataclasses-json/0.5.8/0.5.12?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>lidatong/dataclasses-json (dataclasses-json)</summary>

###
[`v0.5.12`](https://togithub.com/lidatong/dataclasses-json/releases/tag/v0.5.12)

[Compare
Source](https://togithub.com/lidatong/dataclasses-json/compare/v0.5.9...v0.5.12)

##### What's Changed

- Fix multiline scripts in CI by
[@&#8203;george-zubrienko](https://togithub.com/george-zubrienko) in
[lidatong/dataclasses-json#439

**Full Changelog**:
lidatong/dataclasses-json@v0.5.11...v0.5.12

###
[`v0.5.9`](https://togithub.com/lidatong/dataclasses-json/releases/tag/v0.5.9)

[Compare
Source](https://togithub.com/lidatong/dataclasses-json/compare/v0.5.8...v0.5.9)

#### What's Changed

- feat: add formalized issue template by
[@&#8203;s-vitaliy](https://togithub.com/s-vitaliy) in
[lidatong/dataclasses-json#417
- Fixing bug in decoder eval for optional fields by
[@&#8203;rpmcginty](https://togithub.com/rpmcginty) in
[lidatong/dataclasses-json#354
- Fix type order relevance for union wrapping 2 types by
[@&#8203;george-zubrienko](https://togithub.com/george-zubrienko) in
[lidatong/dataclasses-json#419
- Fix autocomplete when using annotation by
[@&#8203;george-zubrienko](https://togithub.com/george-zubrienko) in
[lidatong/dataclasses-json#411
- Add support for enhanced builtin instantiation by
[@&#8203;rpmcginty](https://togithub.com/rpmcginty) in
[lidatong/dataclasses-json#375
- Restore `schema()` type safety by fixing generic type alias misuse by
[@&#8203;andersk](https://togithub.com/andersk) in
[lidatong/dataclasses-json#371

#### New Contributors

- [@&#8203;s-vitaliy](https://togithub.com/s-vitaliy) made their first
contribution in
[lidatong/dataclasses-json#417
- [@&#8203;george-zubrienko](https://togithub.com/george-zubrienko) made
their first contribution in
[lidatong/dataclasses-json#419
- [@&#8203;andersk](https://togithub.com/andersk) made their first
contribution in
[lidatong/dataclasses-json#371

**Full Changelog**:
lidatong/dataclasses-json@v0.5.8...v0.5.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ixm-one/pytest-cmake-presets).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDQuMiIsInVwZGF0ZWRJblZlciI6IjM2LjguMTEiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=-->

Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@rpmcginty rpmcginty deleted the feature/support-enhanced-builtin-instantiation branch November 8, 2023 23:22
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