Giter Site home page Giter Site logo

Add __hash__ in Model about msrest-for-python HOT 6 OPEN

azure avatar azure commented on July 17, 2024 1
Add __hash__ in Model

from msrest-for-python.

Comments (6)

johanste avatar johanste commented on July 17, 2024

Should the hash take read-only/server generated values into account?

from msrest-for-python.

lmazuel avatar lmazuel commented on July 17, 2024

Currently Ansible is happy without (as you noticed, good catch :)). I have no strong opinion, I think __hash__ does not require unicity (contrary to __eq__, we can have hash(a) == hash(b) and a != b). So this is not a requirement for unicity at least. Is it the good thing? Right now I don't know.

from msrest-for-python.

lmazuel avatar lmazuel commented on July 17, 2024

@brettcannon Opinion on this one?

from msrest-for-python.

brettcannon avatar brettcannon commented on July 17, 2024

Are Models considered immutable? If they aren't then you should not be able to hash them. After that all the details of what you need to do for __hash__ is covered by the docs at https://docs.python.org/3/reference/datamodel.html#object.__hash__ (e.g. if a == b then hash(a) == hash(b)).

from msrest-for-python.

lmazuel avatar lmazuel commented on July 17, 2024

@brettcannon It was a note more than deep thought, sorry if I tagged you too ealier before even do some research... So, now I've read your link and the doc 😜

No they aren't immutable. But in most scenario, result from Azure are not changed, so this is interesting. Random ideas:

  • How to raise an exception if we used hash on the obj, and try to change something inside after that? -
  • Add a frozen method to send a frozen read-only model? @nitzmahone @johanste

from msrest-for-python.

brettcannon avatar brettcannon commented on July 17, 2024

You could also implement something like __getstate__ and return a tuple of immutable values (which you could then substantiate from and also gives you the ability to pickle the class if you want that functionality).

from msrest-for-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.