News for hackers. Stuff that matters.
Re:Keep Pydantic out of your Domain Layer by codethief on Sunday July 27, 2025 @08:32AM (#44700866)
You could also use a TypedDict for that, though?

PEP 764[0] will make them extra convenient.

[0]: https://peps.python.org/pep-0764/

Re:Keep Pydantic out of your Domain Layer by JackSlateur on Sunday July 27, 2025 @11:15AM (#44701932)
Typing is declarative

In the end, it ensures nothing and accepts everything

  $ cat test.py
  from typing import TypedDict
  class MyDict(TypedDict):
        some_bool: bool
  print(MyDict(some_bool="test", unknown_field="blabla"))
=>

   $ ./test.py
   {'some_bool': 'test', 'unknown_field': 'blabla'}
Re:Keep Pydantic out of your Domain Layer by codethief on Sunday July 27, 2025 @02:34PM (#44703421)
Rolls eyes… Of course you need to use a type checker. Who doesn't these days?
Re:Keep Pydantic out of your Domain Layer by JackSlateur on Sunday July 27, 2025 @02:52PM (#44703577)
Of course, I need runtime validation
Re:Keep Pydantic out of your Domain Layer by codethief on Monday July 28, 2025 @04:27PM (#44715200)
Sure, runtime validation is useful – at the boundaries of your domain! After that your type checker should ensure your data has the shape your code expects.

In other words: Parse, don't validate. https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-va...

Re:Keep Pydantic out of your Domain Layer by JackSlateur on Wednesday July 30, 2025 @01:49PM (#44737326)
Yes

The boundaries of my domain is everywhere, because stuff are built everywhere. I'm sure I am a bad dev, yet prebuilding all possibles objects I might need everytime I receive an input sounds stupid at best

(btw, this post sounds a lot like "if it compiles, it works", not gonna do this, especially in Python)