Code Monkey home page Code Monkey logo

Comments (13)

FasterSpeeding avatar FasterSpeeding commented on August 16, 2024

Do you have any idea how this would work with builder cache objects? And would we maybe have a method that returns a dict of the raw values or something like that and is on all models?

from hikari.

 avatar commented on August 16, 2024

Do you have any idea how this would work with builder cache objects? And would we maybe have a method that returns a dict of the raw values or something like that and is on all models?

You'd probably have to look at private fields and remove the underscore directly for the constructor to work around this.

from hikari.

FasterSpeeding avatar FasterSpeeding commented on August 16, 2024

Do you have any idea how this would work with builder cache objects? And would we maybe have a method that returns a dict of the raw values or something like that and is on all models?

You'd probably have to look at private fields and remove the underscore directly for the constructor to work around this.

If you're fine with looking at private fields then it shouldn't be too hard to convert the data class over then

from hikari.

 avatar commented on August 16, 2024

Do you have any idea how this would work with builder cache objects? And would we maybe have a method that returns a dict of the raw values or something like that and is on all models?

You'd probably have to look at private fields and remove the underscore directly for the constructor to work around this.

If you're fine with looking at private fields then it shouldn't be too hard to convert the data class over then

It is internal to the library. As long as we do not encourage users to do this, we shouldn't have a problem.

Fields are exposed on the assumption we are responsible developers, tests should highlight bad stuff :^)

from hikari.

Tmpod avatar Tmpod commented on August 16, 2024

I feel like the cons outweight the pros quite a bit in this case. Python is a syntatically simple language in general, and the ease of use is one of its key features, and certainly one that attracts a lot of people. Making the library super verbose by making everything a call to a get_foo() method will substantially reduce the simplicity and pain-less aspect of this library, which I'm afraid will make people gravitate towards solutions like discord.py more in the future. Even though Hikari is, in my opinion, miles better than discord.py due to its fully typed, documented and tested nature, I'm under the impression that it would level out, or even make Hikari less desireable, as its nice pros would be muffled by the high verbosity and "ugliness" of code using it.
I see how this is a quite complicated decision however. Having these calls would simplify stuff and make everything more consistent... You say it's not an anti-pattern per-se and that many modules use it, but I in all honesty, I fail to recall any. Could you point me some?

Thanks 🅱️iscord

from hikari.

 avatar commented on August 16, 2024

You say it's not an anti-pattern per-se and that many modules use it, but I in all honesty, I fail to recall any. Could you point me some?

Pretty much all standard lib modules like asyncio, thread, logging, do this.

Mainly they use future.result() instead of future.get_result() but the concept is the same.

If people are happy that you have to be mindful of how you use event entities, for example, then I am fine with keeping stuff how it is.

An alternative to this may be using custom overrides of __dir__ to exclude properties on instances.

This fixes the introspection issue by allowing inspect.getmembers to skip stuff we deem slow. We could follow what Python's enum type does, which is only specify specific values (in this case slots only, or attrs fields only).

>>>
>>> class Foo:
...     def bar(self): pass
...     def baz(self): pass
...     def bork(self): pass
...     def __dir__(self): return ["bar", "baz"]
...
>>> import inspect
>>>
>>> inspect.getmembers(Foo())
[('bar', <bound method Foo.bar of <__main__.Foo object at 0x7395e7afa0>>), ('baz', <bound method Foo.baz of <__main__.Foo object at 0x7395e7afa0>>)]
# notice no bork

from hikari.

 avatar commented on August 16, 2024

Might close this for the time being and reopen it if I still feel it is relevant.

from hikari.

 avatar commented on August 16, 2024

@FasterSpeeding @davfsa please.

If we are going ahead with this, we need to look into the pros and cons of doing this and ensure we have it noted down before we make a bad decision.

from hikari.

davfsa avatar davfsa commented on August 16, 2024

As I said through Discord on the day this was opened (should have done it through here) I dont really mind one or another. Its true that properties might be a more "pythonish" approach.

I think its fine to have get_x in a lot of cases (eg, get_channel or get_guild). But for simple or inmutable arguments that wont change (eg id) I think its fine to have them as properties.

from hikari.

 avatar commented on August 16, 2024

I think its fine to have get_x in a lot of cases (eg, get_channel or get_guild). But for simple or inmutable arguments that wont change (eg id) I think its fine to have them as properties.

How would you suggest handling events and inheritance hierarchy in this case?

Consider GuildEvent which has a guild property.

Both GuildAvailable and GuildUnavailable provide this attribute in different ways. The former is always aware of the field directly as it is part of the low-level event payload, whereas the latter has to do a cache call for this (calls the GuildEvent default property).

Should these be properties, getter methods, or just remove this from the base class altogether and provide .guild on an available event and .get_guild() on an unavailable event, in your opinion?

from hikari.

davfsa avatar davfsa commented on August 16, 2024

Should these be properties, getter methods, or just remove this from the base class altogether and provide .guild on an available event and .get_guild() on an unavailable event, in your opinion?

In this case I would use get_guild() for both.

I probably did not explain myself correctly before. I meant if its something that we can assure will always be there (eg id) and we dont have to make any calls for it in any variant of the object, then its a property, else, a get_x. That sound better?

Edit: this might cause a lot of inconsistencies. Tbh, i would first do #49 and try to get them as simple as we can to later implement this

from hikari.

 avatar commented on August 16, 2024

@davfsa suggestions on what that involves?

from hikari.

 avatar commented on August 16, 2024

For now I think we have avoided the issue, so will close.

Will reopen if/when this is needed.

from hikari.

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.