Repository: pydantic/pydantic

Issue:
`kw_only=True` does not work in inheritance for `pydantic.Field`
### Initial Checks

- [X] I confirm that I'm using Pydantic V2

### Description

I would like to use `pydantic.Field` over `dataclasses.field`, however, the `kw_only=True` does not work as expected. Possibly related to #7078.

### Example Code

#### Works correctly
```python
import dataclasses
import pydantic

@pydantic.dataclasses.dataclass
class A:
    x: int
    y: int = dataclasses.field(default=0, kw_only=True)

@pydantic.dataclasses.dataclass
class B(A):
    z: int

B(1, 2)
# B(x=1, y=0, z=2)
```

#### Doesn't work
```python
import dataclasses
import pydantic

@pydantic.dataclasses.dataclass
class A:
    x: int
    y: int = pydantic.Field(default=0, kw_only=True)

@pydantic.dataclasses.dataclass
class B(A):
    z: int
# non-default argument 'z' follows default argument
```

### Python, Pydantic & OS Version

```Text
pydantic version: 2.4.2
        pydantic-core version: 2.10.1
          pydantic-core build: profile=release pgo=false
                 install path: /Users/paddy/mambaforge/envs/sleplet/lib/python3.11/site-packages/pydantic
               python version: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:41) [Clang 15.0.7 ]
                     platform: macOS-14.0-arm64-arm-64bit
             related packages: typing_extensions-4.7.1
```



Discussion:
Hi @paddyroddy,

Thanks for reporting this! This does seem like a bug 🐛. We'll work on a fix and keep you updated!

Resolving patch:
diff --git a/pydantic/dataclasses.py b/pydantic/dataclasses.py
--- a/pydantic/dataclasses.py
+++ b/pydantic/dataclasses.py
@@ -12,7 +12,7 @@
 from ._internal import _dataclasses as _pydantic_dataclasses
 from ._migration import getattr_migration
 from .config import ConfigDict
-from .fields import Field
+from .fields import Field, FieldInfo
 
 if TYPE_CHECKING:
     from ._internal._dataclasses import PydanticDataclass
@@ -143,9 +143,29 @@ def dataclass(
 
     if sys.version_info >= (3, 10):
         kwargs = dict(kw_only=kw_only, slots=slots)
+
+        def make_pydantic_fields_compatible(cls: type[Any]) -> None:
+            """Make sure that stdlib `dataclasses` understands `Field` kwargs like `kw_only`
+            To do that, we simply change
+              `x: int = pydantic.Field(..., kw_only=True)`
+            into
+              `x: int = dataclasses.field(default=pydantic.Field(..., kw_only=True), kw_only=True)`
+            """
+            for field_name in cls.__annotations__:
+                try:
+                    field_value = getattr(cls, field_name)
+                except AttributeError:
+                    # no default value has been set for this field
+                    continue
+                if isinstance(field_value, FieldInfo) and field_value.kw_only:
+                    setattr(cls, field_name, dataclasses.field(default=field_value, kw_only=True))
+
     else:
         kwargs = {}
 
+        def make_pydantic_fields_compatible(_) -> None:
+            return None
+
     def create_dataclass(cls: type[Any]) -> type[PydanticDataclass]:
         """Create a Pydantic dataclass from a regular dataclass.
 
@@ -185,6 +205,8 @@ def create_dataclass(cls: type[Any]) -> type[PydanticDataclass]:
                 bases = bases + (generic_base,)
             cls = types.new_class(cls.__name__, bases)
 
+        make_pydantic_fields_compatible(cls)
+
         cls = dataclasses.dataclass(  # type: ignore[call-overload]
             cls,
             # the value of init here doesn't affect anything except that it makes it easier to generate a signature


Test patch:
diff --git a/tests/test_dataclasses.py b/tests/test_dataclasses.py
--- a/tests/test_dataclasses.py
+++ b/tests/test_dataclasses.py
@@ -1644,6 +1644,21 @@ class A:
     assert A(b='hi').b == 'hi'
 
 
+@pytest.mark.skipif(sys.version_info < (3, 10), reason='kw_only is not available in python < 3.10')
+def test_kw_only_subclass():
+    @pydantic.dataclasses.dataclass
+    class A:
+        x: int
+        y: int = pydantic.Field(default=0, kw_only=True)
+
+    @pydantic.dataclasses.dataclass
+    class B(A):
+        z: int
+
+    assert B(1, 2) == B(x=1, y=0, z=2)
+    assert B(1, y=2, z=3) == B(x=1, y=2, z=3)
+
+
 def dataclass_decorators(include_identity: bool = False, exclude_combined: bool = False):
     decorators = [pydantic.dataclasses.dataclass, dataclasses.dataclass]
     ids = ['pydantic', 'stdlib']