Skip to content

Commit d5c8282

Browse files
JensHeinrichJensHeinrich
authored andcommitted
Change rule numbering
1 parent d5ecb1c commit d5c8282

File tree

2 files changed

+49
-45
lines changed

2 files changed

+49
-45
lines changed

README.md

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Bump Pydantic is a tool to help you migrate your code from Pydantic V1 to V2.
2727
- [BP006: Replace `__root__` by `RootModel`](#bp006-replace-__root__-by-rootmodel)
2828
- [BP007: Replace decorators](#bp007-replace-decorators)
2929
- [BP008: Replace `con*` functions by `Annotated` versions](#bp008-replace-con-functions-by-annotated-versions)
30+
- [BP009: Mark pydantic "protocol" functions in custom types with proper TODOs](bp009-mark-pydantic-protocol-functions-in-custom-types-with-proper-todos)
31+
3032
- [License](#license)
3133

3234
---
@@ -301,7 +303,50 @@ class User(BaseModel):
301303
name: Annotated[str, StringConstraints(min_length=1)]
302304
```
303305

304-
<!-- ### BP009: Replace `pydantic.parse_obj_as` by `pydantic.TypeAdapter`
306+
### BP009: Mark pydantic "protocol" functions in custom types with proper TODOs
307+
308+
- ✅ Mark `__get_validators__` as to be replaced by `__get_pydantic_core_schema__`.
309+
- ✅ Mark `__modify_schema__` as to be replaced by `__get_pydantic_json_schema__`.
310+
311+
The following code will be transformed:
312+
313+
```py
314+
class SomeThing:
315+
@classmethod
316+
def __get_validators__(cls):
317+
yield from []
318+
return
319+
320+
@classmethod
321+
def __modify_schema__(
322+
cls, field_schema: Dict[str, Any], field: Optional[ModelField]
323+
):
324+
if field:
325+
field_schema['example'] = "Weird example"
326+
```
327+
328+
Into:
329+
330+
```py
331+
class SomeThing:
332+
@classmethod
333+
# TODO[pydantic]: We couldn't refactor `__get_validators__`, please create the `__get_pydantic_core_schema__` manually.
334+
# Check https://docs.pydantic.dev/latest/migration/#defining-custom-types for more information.
335+
def __get_validators__(cls):
336+
yield from []
337+
return
338+
339+
@classmethod
340+
# TODO[pydantic]: We couldn't refactor `__modify_schema__`, please create the `__get_pydantic_json_schema__` manually.
341+
# Check https://docs.pydantic.dev/latest/migration/#defining-custom-types for more information.
342+
def __modify_schema__(
343+
cls, field_schema: Dict[str, Any], field: Optional[ModelField]
344+
):
345+
if field:
346+
field_schema['example'] = "Weird example"
347+
```
348+
349+
<!-- ### BP010: Replace `pydantic.parse_obj_as` by `pydantic.TypeAdapter`
305350
306351
- ✅ Replace `pydantic.parse_obj_as(T, obj)` to `pydantic.TypeAdapter(T).validate_python(obj)`.
307352
@@ -344,7 +389,7 @@ class Users(BaseModel):
344389
users = TypeAdapter(Users).validate_python({'users': [{'name': 'John'}]})
345390
``` -->
346391

347-
<!-- ### BP010: Replace `PyObject` by `ImportString`
392+
<!-- ### BP011: Replace `PyObject` by `ImportString`
348393
349394
- ✅ Replace `PyObject` by `ImportString`.
350395
@@ -368,48 +413,7 @@ class User(BaseModel):
368413
name: ImportString
369414
``` -->
370415

371-
### BP010: Mark pydantic "protocol" functions in custom types with proper TODOs
372-
373-
- ✅ Mark `__get_validators__` as to be replaced by `__get_pydantic_core_schema__`.
374-
- ✅ Mark `__modify_schema__` as to be replaced by `__get_pydantic_json_schema__`.
375-
376-
The following code will be transformed:
377-
378-
```py
379-
class SomeThing:
380-
@classmethod
381-
def __get_validators__(cls):
382-
yield from []
383-
return
384-
385-
@classmethod
386-
def __modify_schema__(
387-
cls, field_schema: Dict[str, Any], field: Optional[ModelField]
388-
):
389-
if field:
390-
field_schema['example'] = "Weird example"
391-
```
392416

393-
Into:
394-
395-
```py
396-
class SomeThing:
397-
@classmethod
398-
# TODO[pydantic]: We couldn't refactor `__get_validators__`, please create the `__get_pydantic_core_schema__` manually.
399-
# Check https://docs.pydantic.dev/latest/migration/#defining-custom-types for more information.
400-
def __get_validators__(cls):
401-
yield from []
402-
return
403-
404-
@classmethod
405-
# TODO[pydantic]: We couldn't refactor `__modify_schema__`, please create the `__get_pydantic_json_schema__` manually.
406-
# Check https://docs.pydantic.dev/latest/migration/#defining-custom-types for more information.
407-
def __modify_schema__(
408-
cls, field_schema: Dict[str, Any], field: Optional[ModelField]
409-
):
410-
if field:
411-
field_schema['example'] = "Weird example"
412-
```
413417

414418
---
415419

bump_pydantic/codemods/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Rule(str, Enum):
3232
"""Replace `@validator` with `@field_validator`."""
3333
BP008 = "BP008"
3434
"""Replace `con*` functions by `Annotated` versions."""
35-
BP010 = "BP010"
35+
BP009 = "BP009"
3636
"""Mark pydantic 'protocol' functions in custom types with proper TODOs"""
3737

3838

@@ -64,7 +64,7 @@ def gather_codemods(disabled: List[Rule]) -> List[Type[ContextAwareTransformer]]
6464
if Rule.BP007 not in disabled:
6565
codemods.append(ValidatorCodemod)
6666

67-
if Rule.BP010 not in disabled:
67+
if Rule.BP009 not in disabled:
6868
codemods.append(CustomTypeCodemod)
6969

7070
# Those codemods need to be the last ones.

0 commit comments

Comments
 (0)