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

Improve Type Consistency Internally #550

Open
StandingPadAnimations opened this issue Mar 2, 2024 · 0 comments
Open

Improve Type Consistency Internally #550

StandingPadAnimations opened this issue Mar 2, 2024 · 0 comments
Labels
enhancement Feature requests or new functionality suggestions

Comments

@StandingPadAnimations
Copy link
Collaborator

StandingPadAnimations commented Mar 2, 2024

While we did move towards annotations for functions in MCprep (see #425), it seems that we don't properly guarantee these types internally. In addition, there are areas where types can be a bit ambitious, but no checks exist for said types. This means that our type annotations aren't always correct as a source documentation for developers.

In addition, developers with editors that have strict static analysis built in as their LSP will deal with a multitude of warnings and errors relating to types. As an example, here's what my editor shows with the find_from_texturepack function:
image

I'm not suggesting we go all out and disallow dynamic typing (although BpyBuiild does that, but it has the benefit of starting that way), but we can take some steps to improve type consistency.

Some ways we can improve type consistency:

  • Guaranteeing the types we say a function will return will be the types a function returns
    • Performing isinstance checks
    • Checking for None
    • Converting or gracefully return an error if needed
    • Etc.
  • Covering cases where types may not be provided fully, such as with bpy utilities
    • In BpyBuild, we use a typing.cast in areas where a function doesn't provide a type signature or is ambitious, mostly for argparse arguments
    • One particular sore spot with this issue is env.json_data, due to the complexity of the type needed. A good option would be moving from a raw dictionary to a class with the JSON data, though such a migration would have to be done incrementally
@StandingPadAnimations StandingPadAnimations added the enhancement Feature requests or new functionality suggestions label Mar 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests or new functionality suggestions
Projects
Status: Priority proposal
Development

No branches or pull requests

1 participant