Files
pydantic/changes/2890-nuno-andre.md
T
Nuno André bd0a28d8d7 Avoid __dict__ and __weakref__ attributes in AnyUrl and _BaseAddress subclasses (#2890)
* Avoid __dict__ and __weakref__ attributes in AnyUrl and _BaseAddress subclasses

When inheriting from a class with `__slots__`, [child subclasses will get a `__dict__` and `__weakref__` unless they also define `__slots__`](https://docs.python.org/3/reference/datamodel.html#notes-on-using-slots).

```python
from pydantic import AnyUrl, AnyHttpUrl

class AnyOtherHttpUrl(AnyUrl):
    allowed_schemes = {'http', 'https'}
    __slots__ = ()

print(set(dir(AnyHttpUrl)) - set(dir(AnyUrl)))
#> {'__weakref__', '__dict__'}

print(set(dir(AnyOtherHttpUrl)) - set(dir(AnyUrl)))
#> set()
```

* Update changes/2890-nuno-andre.md

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2022-08-04 11:56:37 +00:00

81 B

Avoid __dict__ and __weakref__ attributes in AnyUrl and IP address fields.