Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu committed Mar 8, 2023
2 parents 920e25a + af1c7a1 commit d90a628
Show file tree
Hide file tree
Showing 27 changed files with 428 additions and 229 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: 🐛 Bug
description: Report a bug or unexpected behavior in pydantic
labels: [bug, unconfirmed]
name: 🐛 Pydantic V1.X Bug
description: Report a bug or unexpected behavior in Pydantic V1.X, e.g. all releases prior to V2
labels: [bug V1, unconfirmed]

body:
- type: markdown
Expand All @@ -20,7 +20,7 @@ body:
required: true
- label: I have searched Google & StackOverflow for a solution and couldn't find anything
required: true
- label: I have read and followed [the docs](https://pydantic-docs.helpmanual.io) and still think this is a bug
- label: I have read and followed [the docs](https://docs.pydantic.dev) and still think this is a bug
required: true
- label: >
I am confident that the issue is with pydantic
Expand Down Expand Up @@ -78,14 +78,14 @@ body:
description: Which of the following parts of pydantic does this bug affect?
# keep this lis in sync with feature_request.yml
options:
- label: '[Compatibility between releases](https://pydantic-docs.helpmanual.io/changelog/)'
- label: '[Data validation/parsing](https://pydantic-docs.helpmanual.io/usage/models/#basic-model-usage)'
- label: '[Data serialization](https://pydantic-docs.helpmanual.io/usage/exporting_models/) - `.model_dump()` and `.model_dump_json()`'
- label: '[JSON Schema](https://pydantic-docs.helpmanual.io/usage/schema/)'
- label: '[Dataclasses](https://pydantic-docs.helpmanual.io/usage/dataclasses/)'
- label: '[Model Config](https://pydantic-docs.helpmanual.io/usage/model_config/)'
- label: '[Field Types](https://pydantic-docs.helpmanual.io/usage/types/) - adding or changing a particular data type'
- label: '[Function validation decorator](https://pydantic-docs.helpmanual.io/usage/validation_decorator/)'
- label: '[Generic Models](https://pydantic-docs.helpmanual.io/usage/models/#generic-models)'
- label: '[Other Model behaviour](https://pydantic-docs.helpmanual.io/usage/models/) - `model_construct()`, pickling, private attributes, ORM mode'
- label: '[Plugins](https://pydantic-docs.helpmanual.io/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.'
- label: '[Compatibility between releases](https://docs.pydantic.dev/changelog/)'
- label: '[Data validation/parsing](https://docs.pydantic.dev/usage/models/#basic-model-usage)'
- label: '[Data serialization](https://docs.pydantic.dev/usage/exporting_models/) - `.dict()` and `.json()`'
- label: '[JSON Schema](https://docs.pydantic.dev/usage/schema/)'
- label: '[Dataclasses](https://docs.pydantic.dev/usage/dataclasses/)'
- label: '[Model Config](https://docs.pydantic.dev/usage/model_config/)'
- label: '[Field Types](https://docs.pydantic.dev/usage/types/) - adding or changing a particular data type'
- label: '[Function validation decorator](https://docs.pydantic.dev/usage/validation_decorator/)'
- label: '[Generic Models](https://docs.pydantic.dev/usage/models/#generic-models)'
- label: '[Other Model behaviour](https://docs.pydantic.dev/usage/models/) - `construct()`, pickling, private attributes, ORM mode'
- label: '[Plugins](https://docs.pydantic.dev/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.'
60 changes: 60 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: 🐛 Pydantic V2 Bug
description: Report a bug or unexpected behavior in as-yet unreleased Pydantic V2
labels: [bug V2, unconfirmed]

body:
- type: markdown
attributes:
value: Thank you for contributing to pydantic! ✊

- type: checkboxes
id: checks
attributes:
label: Initial Checks
description: Just making sure you're really using Pydantic V2
options:
- label: I confirm that I'm using Pydantic V2 installed directly from the `main` branch, or equivalent
required: true

- type: textarea
id: description
attributes:
label: Description
description: |
Please explain what you're seeing and what you would expect to see.
Please provide as much detail as possible to make understanding and solving your problem as quick as possible. 🙏
validations:
required: true

- type: textarea
id: example
attributes:
label: Example Code
description: >
If applicable, please add a self-contained,
[minimal, reproducible, example](https://stackoverflow.com/help/minimal-reproducible-example)
demonstrating the bug.
placeholder: |
import pydantic
...
render: Python

- type: textarea
id: version
attributes:
label: Python, Pydantic & OS Version
description: |
Which version of Python & Pydantic are you using, and which Operating System?
Please run the following command and copy the output below:
```bash
python -c "import pydantic.version; print(pydantic.version.version_info())"
```
render: Text
validations:
required: true
31 changes: 17 additions & 14 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: 🚀 Feature request
description: Suggest a new feature or change to pydantic
name: 🚀 Pydantic V2 Feature request
description: |
Suggest a new feature for Pydantic V2
**Note:** Pydantic V2 is currently in development, and we only making critical bug fixes to Pydantic V1. We won't be accepting any new features for Pydantic V1.
labels: [feature request]

body:
Expand All @@ -18,7 +21,7 @@ body:
options:
- label: I have searched Google & GitHub for similar requests and couldn't find anything
required: true
- label: I have read and followed [the docs](https://pydantic-docs.helpmanual.io) and still think this feature is missing
- label: I have read and followed [the docs](https://docs.pydantic.dev) and still think this feature is missing
required: true

- type: textarea
Expand All @@ -42,14 +45,14 @@ body:
description: Which of the following parts of pydantic does this feature affect?
# keep this lis in sync with bug.yml
options:
- label: '[Compatibility between releases](https://pydantic-docs.helpmanual.io/changelog/)'
- label: '[Data validation/parsing](https://pydantic-docs.helpmanual.io/usage/models/#basic-model-usage)'
- label: '[Data serialization](https://pydantic-docs.helpmanual.io/usage/exporting_models/) - `.model_dump()` and `.model_dump_json()`'
- label: '[JSON Schema](https://pydantic-docs.helpmanual.io/usage/schema/)'
- label: '[Dataclasses](https://pydantic-docs.helpmanual.io/usage/dataclasses/)'
- label: '[Model Config](https://pydantic-docs.helpmanual.io/usage/model_config/)'
- label: '[Field Types](https://pydantic-docs.helpmanual.io/usage/types/) - adding or changing a particular data type'
- label: '[Function validation decorator](https://pydantic-docs.helpmanual.io/usage/validation_decorator/)'
- label: '[Generic Models](https://pydantic-docs.helpmanual.io/usage/models/#generic-models)'
- label: '[Other Model behaviour](https://pydantic-docs.helpmanual.io/usage/models/) - `model_construct()`, pickling, private attributes, ORM mode'
- label: '[Plugins](https://pydantic-docs.helpmanual.io/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.'
- label: '[Compatibility between releases](https://docs.pydantic.dev/changelog/)'
- label: '[Data validation/parsing](https://docs.pydantic.dev/usage/models/#basic-model-usage)'
- label: '[Data serialization](https://docs.pydantic.dev/usage/exporting_models/) - `.model_dump()` and `.model_dump_json()`'
- label: '[JSON Schema](https://docs.pydantic.dev/usage/schema/)'
- label: '[Dataclasses](https://docs.pydantic.dev/usage/dataclasses/)'
- label: '[Model Config](https://docs.pydantic.dev/usage/model_config/)'
- label: '[Field Types](https://docs.pydantic.dev/usage/types/) - adding or changing a particular data type'
- label: '[Function validation decorator](https://docs.pydantic.dev/usage/validation_decorator/)'
- label: '[Generic Models](https://docs.pydantic.dev/usage/models/#generic-models)'
- label: '[Other Model behaviour](https://docs.pydantic.dev/usage/models/) - `model_construct()`, pickling, private attributes, ORM mode'
- label: '[Plugins](https://docs.pydantic.dev/) and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.'
24 changes: 17 additions & 7 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# NOTICE
<!-- Thank you for your contribution! -->
<!-- Unless your change is trivial, please create an issue to discuss the change before creating a PR -->
<!-- We're currently in the process of rewriting pydantic in preparation for V2, see https://docs.pydantic.dev/blog/pydantic-v2/. -->
<!-- **Note:** if you're making a pull request to fix pydantic v1.10, please make it against the `1.10.X-fixes` branch. -->

We're currently in the process of rewriting pydantic in preparation for V2, see
https://pydantic-docs.helpmanual.io/blog/pydantic-v2/.
## Change Summary

Please see https://github.com/orgs/pydantic/projects/1 for the major tasks required for this migration.
<!-- Please give a short summary of the changes. -->

To avoid wasting your time, it would be best if you only created significant PRs related to that project.
## Related issue number

Thank you for your interest in pydantic, and your patience. :pray:
<!-- Are there any issues opened that will be resolved by merging this change? -->
<!-- WARNING: please use "fix #123" style references so the issue is closed when this PR is merged. -->

**Note:** if you're making a pull request to fix pydantic v1.10, please make it against the `1.10.X-fixes` branch.
## Checklist

* [ ] Unit tests for the changes exist
* [ ] Tests pass on CI and coverage remains at 100%
* [ ] Documentation reflects the changes where applicable
* [ ] `changes/<pull request or issue id>-<github username>.md` file added describing change
(see [changes/README.md](https://github.com/samuelcolvin/pydantic/blob/master/changes/README.md) for details)
* [ ] My PR is ready to review, **please add a comment including the phrase "please review" to assign reviewers**
2 changes: 1 addition & 1 deletion .github/workflows/cherry-pick.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0

- name: Cherry pick into 1.10.X-fixes
uses: carloscastrojumo/github-cherry-pick-action@v1.0.6
uses: carloscastrojumo/github-cherry-pick-action@v1.0.9
with:
branch: 1.10.X-fixes
labels: from-cherry-pick
Expand Down
41 changes: 30 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ jobs:
path: site

test:
name: test py${{ matrix.python-version }} on ${{ matrix.os }}
name: test ${{ matrix.os }} / ${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', 'pypy3.7', 'pypy3.8', 'pypy3.9']
# no pydantic-core binaries for pypy on windows, so tests take absolute ages
exclude:
- os: windows
python-version: 'pypy3.7'
- os: windows
python-version: 'pypy3.8'
- os: windows
python-version: 'pypy3.9'

env:
PYTHON: ${{ matrix.python-version }}
Expand Down Expand Up @@ -143,21 +151,32 @@ jobs:
name: coverage
path: coverage

test-old-mypy:
name: test mypy v${{ matrix.mypy-version }}
test-mypy:
name: mypy v${{ matrix.mypy-version }} / ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
mypy-version: ['0.950', '0.961', '0.971', '0.982', '0.991']
# test recent mypy versions on 3.10 and mypy 1.0.1 on all supported python versions
mypy-version: ['0.971', '0.982', '0.991', '1.0.1']
python-version: ['3.10']
include:
- mypy-version: '1.0.1'
python-version: '3.7'
- mypy-version: '1.0.1'
python-version: '3.8'
- mypy-version: '1.0.1'
python-version: '3.9'
- mypy-version: '1.0.1'
python-version: '3.11'

steps:
- uses: actions/checkout@v3

- name: set up python
uses: actions/setup-python@v4
with:
python-version: '3.10'
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v3
id: cache
Expand All @@ -182,10 +201,10 @@ jobs:
- run: mkdir coverage

- name: run tests
run: coverage run -m pytest tests/mypy
run: coverage run -m pytest tests/mypy --test-mypy
env:
COVERAGE_FILE: coverage/.coverage.linux-py3.10-mypy${{ matrix.mypy-version }}
CONTEXT: linux-py3.10-mypy${{ matrix.mypy-version }}
COVERAGE_FILE: coverage/.coverage.linux-py${{ matrix.python-version }}-mypy${{ matrix.mypy-version }}
CONTEXT: linux-py${{ matrix.python-version }}-mypy${{ matrix.mypy-version }}

- name: store coverage files
uses: actions/upload-artifact@v3
Expand All @@ -194,7 +213,7 @@ jobs:
path: coverage

coverage-combine:
needs: [test, test-old-mypy]
needs: [test, test-mypy]
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -255,7 +274,7 @@ jobs:
- lint
- docs-build
- test
- test-old-mypy
- test-mypy
- test-fastapi

runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/upload-previews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
env:
SMOKESHOW_GITHUB_STATUS_DESCRIPTION: Coverage {coverage-percentage}
# 5 is set here while V2 is in development and coverage is far from complete
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 5
SMOKESHOW_GITHUB_COVERAGE_THRESHOLD: 84
SMOKESHOW_GITHUB_CONTEXT: coverage
SMOKESHOW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SMOKESHOW_GITHUB_PR_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
Expand Down
1 change: 1 addition & 0 deletions changes/5120-cdce8p.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `dataclass_transform` decorator for pydantic dataclasses
4 changes: 2 additions & 2 deletions pydantic/_internal/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def __init__(self, schema: CoreSchema | TypedDictField):
@property
def metadata(self) -> _CoreMetadata:
"""
Retrieves the metadata dict off the schema, initializing it to a dict if necessary,
and erroring if it is not None and not a dict
Retrieves the metadata dict off the schema, initializing it to a dict if it is None
and raises an error if it is not a dict.
"""
metadata = self._schema.get('metadata')
if metadata is None:
Expand Down
18 changes: 6 additions & 12 deletions pydantic/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class M:
The trick is to create a wrapper around `M` that will act as a proxy to trigger
validation without altering default `M` behaviour.
"""
import dataclasses
import sys
from contextlib import contextmanager
from functools import wraps
Expand Down Expand Up @@ -105,7 +106,7 @@ def __validate__(cls: Type['DataclassT'], v: Any) -> 'DataclassT':

if sys.version_info >= (3, 10):

@dataclass_transform(kw_only_default=True, field_specifiers=(Field, FieldInfo))
@dataclass_transform(field_specifiers=(dataclasses.field, Field))
@overload
def dataclass(
*,
Expand All @@ -121,7 +122,7 @@ def dataclass(
) -> Callable[[Type[_T]], 'DataclassClassOrWrapper']:
...

@dataclass_transform(kw_only_default=True, field_specifiers=(Field, FieldInfo))
@dataclass_transform(field_specifiers=(dataclasses.field, Field))
@overload
def dataclass(
_cls: Type[_T],
Expand All @@ -140,7 +141,7 @@ def dataclass(

else:

@dataclass_transform(kw_only_default=True, field_specifiers=(Field, FieldInfo))
@dataclass_transform(field_specifiers=(dataclasses.field, Field))
@overload
def dataclass(
*,
Expand All @@ -155,7 +156,7 @@ def dataclass(
) -> Callable[[Type[_T]], 'DataclassClassOrWrapper']:
...

@dataclass_transform(kw_only_default=True, field_specifiers=(Field, FieldInfo))
@dataclass_transform(field_specifiers=(dataclasses.field, Field))
@overload
def dataclass(
_cls: Type[_T],
Expand All @@ -172,7 +173,7 @@ def dataclass(
...


@dataclass_transform(kw_only_default=True, field_specifiers=(Field, FieldInfo))
@dataclass_transform(field_specifiers=(dataclasses.field, Field))
def dataclass(
_cls: Optional[Type[_T]] = None,
*,
Expand All @@ -195,8 +196,6 @@ def dataclass(
the_config = get_config(config)

def wrap(cls: Type[Any]) -> 'DataclassClassOrWrapper':
import dataclasses

if is_builtin_dataclass(cls) and _extra_dc_args(_cls) == _extra_dc_args(_cls.__bases__[0]): # type: ignore
dc_cls_doc = ''
dc_cls = DataclassProxy(cls)
Expand Down Expand Up @@ -314,7 +313,6 @@ def new_init(self: 'Dataclass', *args: Any, **kwargs: Any) -> None:
if hasattr(self, '__post_init_post_parse__'):
# We need to find again the initvars. To do that we use `__dataclass_fields__` instead of
# public method `dataclasses.fields`
import dataclasses

# get all initvars and their default values
initvars_and_values: Dict[str, Any] = {}
Expand Down Expand Up @@ -364,8 +362,6 @@ def create_pydantic_model_from_dataclass(
config: Optional[ConfigDict] = None,
dc_cls_doc: Optional[str] = None,
) -> Type['BaseModel']:
import dataclasses

if config is None:
config = ConfigDict()

Expand Down Expand Up @@ -467,8 +463,6 @@ class B(A):
In this case, when we first check `B`, we make an extra check and look at the annotations ('y'),
which won't be a superset of all the dataclass fields (only the stdlib fields i.e. 'x')
"""
import dataclasses

return (
dataclasses.is_dataclass(_cls)
and not hasattr(_cls, '__pydantic_model__')
Expand Down
Loading

0 comments on commit d90a628

Please sign in to comment.