Skip to content

pubsub.Topic.create() returns None? #837

Closed

Description

@jgeewax

I'd really like to write

topic = pubsub.Topic('topic').create()

Looks like from the code we have today, that we don't return anything, so this won't work (topic will be None right here).

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    api: pubsubIssues related to the Pub/Sub API.
    on Apr 17, 2015
  2. added this to the milestone on Apr 17, 2015
  3. dhermes commented on Apr 17, 2015

    @dhermes
    Contributor

    We've spoken a bit about this. That is un-Pythonic.

    For example, see from the standard library.

    >>> a = [1, -1, 10, 6]
    >>> b = a.sort()
    >>> b is None
    True
    >>> a
    [-1, 1, 6, 10]
  4. jgeewax commented on Apr 17, 2015

    @jgeewax
    ContributorAuthor

    Being able to chain things nicely is un-Pythonic? Do we have more references to why this is a bad idea? Can you point me to that discussion?

    It looks like Boto does this... See:

  5. dhermes commented on Apr 17, 2015

    @dhermes
    Contributor

    Having been inside, boto is not a very Pythonic library. Method chaining is a JavaScript idiom, not Python.

  6. jgeewax commented on Apr 17, 2015

    @jgeewax
    ContributorAuthor

    That doesn't really answer things for me ... :(

    I think the bigger issue is that I don't see a use for a Topic object that isn't 'created'. that is, what can I do with topic = pubsub.Topic('name') besides create it?

    Would this method be better as a factory?

    topic = pubsub.Topic.create('topic-name')

    or

    topic = pubsub.create_topic('topic-name')

    ?

  7. dhermes commented on Apr 17, 2015

    @dhermes
    Contributor
    1. Yeah I was going to point out pubsub.create_topic('topic-name')
    2. I'll let @tseaver speak on the design, but for us, the point of a method like topic.create() is to make it clear to the user when they are making an HTTP request and when they are just updating a local property of a Topic object.

    So they have the option of "functional" approach pubsub.create_topic('topic-name') or OO approach topic.create()

  8. jgeewax commented on Apr 17, 2015

    @jgeewax
    ContributorAuthor

    Yeah I was going to point out pubsub.create_topic('topic-name')

    Does that exist? I don't see it...

    the point of a method like topic.create() is to make it clear to the user when they are making an HTTP request and when they are just updating a local property of a Topic object.

    Totally agree - I don't want to hide that a request is being made.

    Wouldn't the two options go against the whole "one way to do things" idea?

  9. dhermes commented on Apr 17, 2015

    @dhermes
    Contributor

    Indeed they would violate the Zen of Python "There should be one-- and preferably only one --obvious way to do it.". @tseaver has mentioned abolishing functions of the form

    top_level_package.verb_thing(args)

    in favor of

    thing = top_level_package.Thing(...)
    thing.verb(args)
  10. jgeewax commented on Apr 17, 2015

    @jgeewax
    ContributorAuthor

    What's the reason for that ?

    If we're going to go that way, I'd like to re-open the topic of enforcing all our methods to be chainable. I'd rather go the package.verb_thing(args) though....

  11. dhermes commented on Dec 31, 2015

    @dhermes
    Contributor

    Closing this as #911 due to lost steam

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: pubsubIssues related to the Pub/Sub API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Sponsor
    SponsoredKunjungi sekarang
    Promo