KEMBAR78
Add `deprecated` marker for fields in a model · Issue #2255 · pydantic/pydantic · GitHub
Skip to content

Add deprecated marker for fields in a model #2255

@gautamsinghania95

Description

@gautamsinghania95

Checks

  • I added a descriptive title to this issue
  • I have searched (google, github) for similar issues and couldn't find anything
  • I have read and followed the docs and still think this feature/change is needed
  • After submitting this, I commit to one of:
    • Look through open issues and helped at least one other person
    • Hit the "watch" button on this repo to receive notifications and I commit to help at least 2 people that ask questions in the future
    • Implement a Pull Request for a confirmed bug

Feature Request

Pydantic Fields should have a boolean option deprecated (default False) which can be used to mark deprecated fields. Pydantic plugin for Pycharm can also use this field to see if the field should be used any longer, and show code hints if someone is trying to interact with deprecated fields.

Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":

$ python -c "import pydantic.utils; print(pydantic.utils.version_info())"
             pydantic version: 1.6.1
            pydantic compiled: True
                 install path: ...
               python version: 3.6.8 |Anaconda, Inc.| (default, Dec 29 2018, 19:04:46)  [GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)]
                     platform: Darwin-19.6.0-x86_64-i386-64bit
     optional deps. installed: ['typing-extensions']

Sample Code Snippet

from pydantic import BaseModel, Field

class MyModel(BaseModel):
     oldField: Optional[int] = Field(None, deprecated=True, description="Use `newField` instead of this")
     newField: Dict[str, int] = Field({}, description="New field to accept string to key values")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions