Closed David-Woroniuk closed 2 years ago
Hi @David-Woroniuk, thanks for the excellent suggestion. It would be great if you could submit a PR request. And please do let us know if you have other ideas for improving the package!
@ranjitlall - PR is with you now - please push through your unit tests ahead of merging.
Firstly, a great package.
I noticed that the package uses
if type(var) == float:
, and thought it may be useful to modify the behaviour to be more Pydantic.To summarise,
isinstance
caters for inheritance (where an instance of a derived class is an instance of a base class), while checking for equality oftype
does not. This instead demands identity of types and rejects instances of subclasses.Typical Python code should support inheritance, so
isinstance
is less bad than checking types, as it supports inheritance. However, “duck typing” would be the preferred (try, except), catching all exceptions associated with an incorrect type (TypeError).I refer to lines 142-153, whereby the list type is evaluated:
which could be achieved more elegantly using:
181-187:
whereby the type (or types) could be hinted to the user within the init dunder method, and can be evaluated through:
Depending on the python versions supported, I would also recommend using typehints, and using the below:
More than happy to submit a PR with the proposed changes.