Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

__str__ and __repr__ are squashed on child classes #1022

Closed
khaeru opened this issue Nov 22, 2019 · 1 comment · Fixed by #1023
Closed

__str__ and __repr__ are squashed on child classes #1022

khaeru opened this issue Nov 22, 2019 · 1 comment · Fixed by #1023
Labels
bug

Comments

@khaeru
Copy link

@khaeru khaeru commented Nov 22, 2019

After #884, a child class of a model does not inherit its parent's __str__ and __repr__ overloads.

import pydantic

class Foo(pydantic.BaseModel):
    x: int = 3
    y: float = 4.2

    def __str__(self):
        return str(self.y + self.x)


f = Foo()
# Expected: 7.2
# Observed: 7.2
print(str(f))


class Bar(Foo):
    z: bool = False


b = Bar()

# Expected: 7.2
# Observed: x=3 y=4.2 z=False
print(str(b))
  • OS: Ubuntu 19.10
  • Python version import sys; print(sys.version): 3.7.5 (default, Nov 20 2019, 09:21:52) [GCC 9.2.1 20191008]
  • Pydantic version import pydantic; print(pydantic.VERSION): 1.1.1
@khaeru khaeru added the bug label Nov 22, 2019
samuelcolvin added a commit that referenced this issue Nov 22, 2019
@samuelcolvin

This comment has been minimized.

Copy link
Owner

@samuelcolvin samuelcolvin commented Nov 22, 2019

thanks for reporting, should be fixed in #1023, please check that works for you.

samuelcolvin added a commit that referenced this issue Nov 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.