You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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
The text was updated successfully, but these errors were encountered:
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: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:
isinstance
checksNone
bpy
utilitiestyping.cast
in areas where a function doesn't provide a type signature or is ambitious, mostly forargparse
argumentsenv.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 incrementallyThe text was updated successfully, but these errors were encountered: