Skip to content
This repository was archived by the owner on Oct 13, 2026. It is now read-only.
This repository was archived by the owner on Oct 13, 2026. It is now read-only.

pylint: Instance of 'SubscriberClient' has no 'subscription_path' member #67

Closed

Description

@dinvlad

Environment details

  • OS type and version: macOS Mojave 10.14.6
  • Python version: python --version 3.7.7
  • pip version: pip --version 20.0.2
  • google-cloud-pubsub version: pip show google-cloud-pubsub 1.4.2

Steps to reproduce

  1. Use the stock subscription example from https://github.com/googleapis/python-pubsub/blob/master/docs/subscriber/index.rst
  2. Running pylint on it results in:
E1101: Instance of 'SubscriberClient' has no 'subscription_path' member (no-member)

Code example

from google.cloud import pubsub
subscriber = pubsub.SubscriberClient()

sub_path = subscriber.subscription_path(PROJECT, SUBSCRIPTION)

Stack trace

N/A

Activity

  1. dinvlad commented on Apr 8, 2020

    @dinvlad
    Author
  2. added
    type: questionRequest for information or clarification. Not an issue.
    on Apr 8, 2020
  3. anguillanneuf commented on Apr 14, 2020

    @anguillanneuf
    Contributor

    @dinvlad Thanks for your question.

    subscription_path is defined in cloud/pubsub_v1/gapic/subscriber_client.py:

    @classmethod
    def subscription_path(cls, project, subscription):
    """Return a fully-qualified subscription string."""
    return google.api_core.path_template.expand(
    "projects/{project}/subscriptions/{subscription}",
    project=project,
    subscription=subscription,
    )

    This method is being added in cloud/pubsub_v1/subscriber/client.py via the decorator:

    @_gapic.add_methods(subscriber_client.SubscriberClient, blacklist=_BLACKLISTED_METHODS)
    class Client(object):

    You should be able to see the method if you run dir(subscriber). Does this help?

  4. dinvlad commented on Apr 15, 2020

    @dinvlad
    Author

    I think the issue is the typings, not necessarily that the method is not there (as it is). So I'd like to re-open this if possible, since the way this method is wired currently makes it incompatible with pylint.

  5. dinvlad commented on Apr 15, 2020

    @dinvlad
    Author

    Specifically, unlike the subscribe() method, the subscription_path() method is not wired directly into https://github.com/googleapis/python-pubsub/blob/master/google/cloud/pubsub_v1/subscriber/client.py, but rather through the @_gapic annotation.. I'm not sure if this would be easy to fix?

  6. anguillanneuf commented on Apr 15, 2020

    @anguillanneuf
    Contributor

    @plamut @pradn Please mark this as a consideration for Pub/Sub v2.

    @dinvlad We really should be compatible with pylint because of pylint's widespread usage 😞But for Version 1 of our library, this is probably not going to happen as it doesn't affect the functionality of the library. We are currently designing v2 - compatibility with third party tools will make into our considerations. Thank you again for raising it.

  7. dinvlad commented on Apr 15, 2020

    @dinvlad
    Author

    I see, thank you for explaining @anguillanneuf ! We'll keep this in mind.

    As a workaround, we may probably switch to another linter for now - I think this library itself uses pep8 if I'm not mistaken?

  8. anguillanneuf commented on Apr 15, 2020

    @anguillanneuf
    Contributor

    No problem @dinvlad ! We use nox, which complies to PEP8, see the Contributing Guide.

  9. plamut commented on Apr 16, 2020

    @plamut
    Contributor

    @dinvlad The classes in gapic/ directory are auto-generated based on the .proto definitions, including the SubscriberClient class, and there is a manual layer on top of that - the Client class from subscriber/client.py.

    In order to avoid code duplication and to prevent the manual and generated client classes going out of sync, methods from the auto-generated class need to be automatically injected into the manual layer through the @_gapic.add_methods decorator. It's not surprising that such dynamic magic confuses the static linter. It's also not something that can be easily fixed in the library itself.

    Of course, littering the source with numerous # pylint: disable=no-member comments is not appealing, but fortunately pylint can be configured to ignore that with the --generated-members setting. If you can stick to a common name for subscriber instances in your app, writing a regex that matches method invocations on them should do the trick.

    Would that be feasible for your case?

  10. nicpreuss commented on Sep 24, 2020

    @nicpreuss

    @anguillanneuf just ran into the same issue and found out this thread....I was wondering if there is any update on a release of the v2 allowing the fix to work with pylint?

  11. anguillanneuf commented on Sep 28, 2020

    @anguillanneuf
    Contributor

    @nicpreuss On v2 there isn't. But thank you for raising it so it stays on our radar.

  12. g2github commented on Oct 22, 2020

    @g2github

    I'm having this same issue, but am not clear what the "fix" is. How do I get past this error?

  13. nicpreuss commented on Oct 23, 2020

    @nicpreuss

    @g2github hey probably not a best practice but here is how I hacked this
    topic_path = publisher.topic_path(project_id, topic_id)# pylint: disable=no-member

    the pylint: disable=no-member allows you to override the error.

  14. g2github commented on Oct 23, 2020

    @g2github

    thanks @nicpreuss

  15. nicpreuss commented on Oct 23, 2020

    @nicpreuss

    let me know if it works for you or if you find a better solution @g2github

  16. g2github commented on Oct 23, 2020

    @g2github

    looks like i need # pylint: disable=no-member all over my code... how can this be possible?

  17. dinvlad commented on Feb 11, 2021

    @dinvlad
    Author

    Any updates here?

  18. plamut commented on Feb 11, 2021

    @plamut
    Contributor

    @dinvlad About the ways to fix the error or the v2 client?

    AFAIK v2 client cannot be expected yet in the near/mid future, while IMHO the best way to silence false pylint errors is by leveraging the generated-members setting - better than littering the code with pylint: disable=no-member, unless there are only a few occurrences.

    (I can ask about the v2 client for a more reliable answer, however)

  19. dinvlad commented on Feb 11, 2021

    @dinvlad
    Author

    Thanks, that would be much appreciated!

  20. plamut commented on Feb 12, 2021

    @plamut
    Contributor

    Update: The V2 client is currently still in the planning phase, and the earliest implementation is not expected before Q3/2021 (best case scenario).

  21. MiltiadisKoutsokeras commented on Jan 11, 2022

    @MiltiadisKoutsokeras

    Hi all,

    In case someone is reading this, the problem with pylint still persists using google-cloud-pubsub==2.9.0.

    Instance of 'PublisherClient' has no 'topic_path' member

  22. plamut commented on Jan 11, 2022

    @plamut
    Contributor

    @MiltiadisKoutsokeras Would you also mind to check with the tip of the main branch? (not released yet)

    Recently, a considerable refactoring of the clients was merged - the hand-written classes now directly inherit from the generated classes, instead of dynamically injecting the generated methods into their namespace (static type checkers couldn't actually know that).

    Simplifying the code should not confuse static type checkers anymore.

    Edit: Sorry, was looking at the wrong PR. That particular PR is not merged yet, but at least there is a working solution out there. I will nudge the folks to review the changes.

  23. adamwojt commented on Apr 15, 2022

    @adamwojt

    Same with pyright here with google-cloud-pubsub==2.8.0.
    image

  24. iamtodor commented on Jan 23, 2023

    @iamtodor

    @adamwojt in your case it's because of topic_path() is @staticmethod

        @staticmethod
        def topic_path(
            project: str,
            topic: str,
        ) -> str:
            """Returns a fully-qualified topic string."""
            return "projects/{project}/topics/{topic}".format(
                project=project,
                topic=topic,
            )

    But treating it as static also does not work properly:

    topic_path = pubsub_v1.PublisherClient.topic_path(PROJECT_ID, "blah")
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 googleapis/python-pubsub API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions