CoEDL / elpis

🙊 software for creating speech recognition models.
https://elpis.readthedocs.io/en/latest/
Apache License 2.0
152 stars 33 forks source link

Force usage keyword agruments only in API #71

Closed shuttle1987 closed 3 years ago

shuttle1987 commented 4 years ago

If you haven't got a released API you can force the users to use keyword only arguments. This makes forwards/backwards compatibility far easier and will allow you much easier deprecation options in the future if you require them.

For example I'd change this:

https://github.com/CoEDL/elpis/blob/913c567bfaafc2081bc96fbd80036b07d4762bf0/elpis/wrappers/objects/fsobject.py#L20-L26

To something like this:

 def __init__(self,
              *, 
              parent_path: Path = None, 
              dir_name: str = None, 
              name: str = None, 
              logger: Logger = None, 
              pre_allocated_hash: str = None 
              ): 

As this gives you substantially more flexibility going forward with your API decisions and at far less cost to people who have to implement the call site code.

Specifically in the future if you wish to change any of these arguments then the call sites have to change since the ordering of the arguments must be preserved if people use positional arguments, or worse user code starts failing because the parameters now have different meanings. If you force keyword arguments from the beginning then this entire source of problems is removed.