Skip to content

Commit

Permalink
Revert "Fix PEP487 __set_name__ protocol in BaseModel (#4407)" (#4411)
Browse files Browse the repository at this point in the history
This reverts commit d501c39.
  • Loading branch information
samuelcolvin committed Aug 22, 2022
1 parent d501c39 commit 61dafce
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 27 deletions.
1 change: 0 additions & 1 deletion changes/4407-tlambert03.md

This file was deleted.

6 changes: 0 additions & 6 deletions pydantic/main.py
Expand Up @@ -286,12 +286,6 @@ def is_untouched(v: Any) -> bool:
if resolve_forward_refs:
cls.__try_update_forward_refs__()

# preserve `__set_name__` protocol defined in https://peps.python.org/pep-0487
for name, obj in namespace.items():
set_name = getattr(obj, '__set_name__', None)
if callable(set_name):
set_name(cls, name)

return cls

def __instancecheck__(self, instance: Any) -> bool:
Expand Down
20 changes: 0 additions & 20 deletions tests/test_create_model.py
Expand Up @@ -3,7 +3,6 @@
import pytest

from pydantic import BaseModel, Extra, Field, ValidationError, create_model, errors, validator
from pydantic.fields import ModelPrivateAttr
from pydantic.generics import GenericModel


Expand Down Expand Up @@ -223,22 +222,3 @@ class TestGenericModel(GenericModel):
result = AAModel[int](aa=1)
assert result.aa == 1
assert result.__config__.orm_mode is True


def test_set_name():
calls = []

class class_deco(ModelPrivateAttr):
def __init__(self, fn):
super().__init__()
self.fn = fn

def __set_name__(self, owner, name):
calls.append((owner, name))

class A(BaseModel):
@class_deco
def _some_func(self):
return self

assert calls == [(A, '_some_func')]

0 comments on commit 61dafce

Please sign in to comment.