Coverage for src\pncp\tipos.py: 86%

1 from typing import Any, Callable, Self

2

3 from pydantic import BaseModel

4

5

6 class Lista[X](list[X]):

7 def filtrar(self, funcao: Callable[[X], bool]) -> "Lista[X]":

8 return Lista(filter(funcao, self))

9

10 def transformar[Y](self, funcao: Callable[[X], Y]) -> "Lista[Y]":

11 return Lista(map(funcao, self))

12

13

14 def para_camel_case(string_em_snake_case: str) -> str:

15 parts = string_em_snake_case.split("_")

16 if not parts:

17 return ""

18 return parts[0] + "".join(word[0].upper() + word[1:] for word in parts[1:])

19

20

21 class ModeloBasico(BaseModel):

22 class Config:

23 arbitrary_types_allowed = True

24 populate_by_name = True

25 alias_generator = para_camel_case

26

27 def como_dicionario(self) -> dict[str, Any]:

28 return self.model_dump()

29

30 @classmethod

31 def de_dicionario(cls, dicionario: dict[str, Any]) -> Self:

32 return cls.model_validate(dicionario)