Skip to content

Evaluating Pyright vs Mypy for preexisting codebase with too-dynamic model base class #8031

Answered by erictraut
jrheard-seesaw asked this question in Q&A
Discussion options

You must be logged in to vote

Without more details about how the library works, it's difficult to offer any concrete suggestions, but I can offer some general ideas that might be useful to you.

  1. You can make BaseModel derive from Any (conditionally, if TYPE_CHECKING is True). This will tell static type checkers to allow access (read or write) to any additional attributes on BaseModel subclasses and treat these attributes as Any.
  2. Similarly, you could define a __getattr__ method in the BaseModel class (conditionally, if TYPE_CHECKING is True). This gives you a bit more control than the previous option because you can overload it for specific attributes (using Literal names). It also allows you to make any additional att…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@jrheard-seesaw
Comment options

@erictraut
Comment options

Answer selected by jrheard-seesaw
@jrheard-seesaw
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants