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

refactor: mismatching of signature of base method #162

Merged
merged 1 commit into from Jan 17, 2024

Conversation

nautics889
Copy link
Contributor

@nautics889 nautics889 commented Jan 15, 2024

Description

Signature of create() method in RODetailEndpoint does not match the one in parent class DetailEndpoint.

...
class DetailEndpoint(object):
    ...
    def create(self, data=None, api_version=None):
        ...

vs

...
class RODetailEndpoint(DetailEndpoint):
    ...
    def create(self, data):
        ...

Originally they matched each other, when RODetailEndpoint had been added (3862901 Dec '18). But later it was updated from def create(self, data) to def create(self, data=None, api_version=None) in DetailEndpoint base class (12305bc Apr '22).

This potentially leads to a violation of LSP.


Examples

Let's suppose user tries to call create() of RODetailEndpoint passing api_version.

Expected behavior:

>>> ro_endpoint.create({"what": "ever"}, api_version="1.2.3")
Traceback (most recent call last):
  ...
NotImplementedError: Writes are not supported for this endpoint.

(user discovers he's trying to call not supported method)

Current behavior:

>>> ro_endpoint.create({"what": "ever"}, api_version="1.2.3")
Traceback (most recent call last):
  ...
TypeError: RODetailEndpoint.create() got an unexpected keyword argument 'api_version'

(user encounters on TypeError instead)


  • (refactor): update signature of create() in RODetailEndpoint class, make it match the one in DetailEndpoint base class

* (refactor): update signature of `create()` in `RODetailEndpoint`
  class, make it match the one in `DetailEndpoint` base class
@nautics889 nautics889 marked this pull request as ready for review January 15, 2024 21:57
Copy link
Contributor

@pszulczewski pszulczewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joewesch joewesch merged commit fde8446 into nautobot:develop Jan 17, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants