How to avoid pylint not-an-iterable when using a custom property class

Alon

My code uses the commonly used cached_property class from werkzeug. Consider the following snippet:

from werkzeug import cached_property

class SampleClass(object):
    @cached_property
    def list_prop(self):
        return [1, 2]

sample = SampleClass()
for item in sample.list_prop:
    print item

I use pylint in my CI process. If I run the pylint not-an-iterable check on this code, it fails even though the code is perfectly fine.

$ pylint --disable=all --enable=not-an-iterable prop.py
************* Module prop
E:  9,12: Non-iterable value sample.list_prop is used in an iterating context (not-an-iterable)

pylint works well when checking the same code with the built-in @property decorator instead of @cached_property:

class SampleClass(object):
    @property
    def list_prop(self):
        return [1, 2]

What should I do to help pylint overcome this false positive?

Srikanth

Looks like you are importing cached_property incorrectly. It lives in werkzeug.utils. pylint caught that error: E: 1, 0: No name 'cached_property' in module 'werkzeug' (no-name-in-module). Here's the fixed code:

from werkzeug.utils import cached_property

class SampleClass(object):
    @cached_property
    def list_prop(self):
        return [1, 2]

sample = SampleClass()
for item in sample.list_prop:
    print item

When I run pylint after applying this fix, it stops complaining:

$ pylint test
No config file found, using default configuration
************* Module test
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Missing class docstring (missing-docstring)
C:  5, 4: Missing method docstring (missing-docstring)
R:  3, 0: Too few public methods (1/2) (too-few-public-methods)
C:  8, 0: Invalid constant name "sample" (invalid-name)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to avoid coupling when using useReducer?

分類Dev

How to correctly make a condition by using the class property ?

分類Dev

How to avoid slow collapse when using bootstrap collapse and div in a table

分類Dev

Nodejs: How to avoid nested .then() when using async/await

分類Dev

How to Avoid Recreating Object When Using Let with LINQ

分類Dev

How to avoid using a var when doing multiple string replacements in a string

分類Dev

IB Designables gives strange warning when using a custom class

分類Dev

How to update custom property of docx file using php

分類Dev

How can I get each property of class that has custom Attribute then show them in dropdown?

分類Dev

How to create element and set custom attribute to map a simple type class property

分類Dev

How to define a property to avoid: Property 'X' does not exist on type 'Y'

分類Dev

How to avoid class name in @type while serializing object to JSON using Jackson

分類Dev

How can I access a globally defined property that is accessed through a property file using Spock when unit testing

分類Dev

How to write custom code (logic) when using firebase

分類Dev

Django: How to limit_choices_to when using custom intermediate table

分類Dev

How to keep custom object sequence property in model when there are multiple lists of that type used in application

分類Dev

Avoid showing UIAlertView when using PFLogInViewController

分類Dev

How to avoid hardcode in every class WebClient retryWhen

分類Dev

How to avoid warning about no return expression when using static_assert?

分類Dev

How to avoid "Invalid byte sequence" when looking for link with text using Nokogiri

分類Dev

How to avoid dropping items when using core.async pub/sub?

分類Dev

How do I avoid absolute pathnames in my code when using Git?

分類Dev

How to define an interface as a class property?

分類Dev

Custom property delegation for arrays using a map

分類Dev

Using custom property value to set a color in a template

分類Dev

How to know when all Promises are Resolved in a dynamic "iterable" parameter?

分類Dev

How do I get a property at index using custom validation in ASP.NET Core?

分類Dev

How to access property of suggestions coming from my AutoSuggest ( custom made using .filter() )

分類Dev

What is the nature of a class property when declared with "= {}()" in Swift?

Related 関連記事

  1. 1

    How to avoid coupling when using useReducer?

  2. 2

    How to correctly make a condition by using the class property ?

  3. 3

    How to avoid slow collapse when using bootstrap collapse and div in a table

  4. 4

    Nodejs: How to avoid nested .then() when using async/await

  5. 5

    How to Avoid Recreating Object When Using Let with LINQ

  6. 6

    How to avoid using a var when doing multiple string replacements in a string

  7. 7

    IB Designables gives strange warning when using a custom class

  8. 8

    How to update custom property of docx file using php

  9. 9

    How can I get each property of class that has custom Attribute then show them in dropdown?

  10. 10

    How to create element and set custom attribute to map a simple type class property

  11. 11

    How to define a property to avoid: Property 'X' does not exist on type 'Y'

  12. 12

    How to avoid class name in @type while serializing object to JSON using Jackson

  13. 13

    How can I access a globally defined property that is accessed through a property file using Spock when unit testing

  14. 14

    How to write custom code (logic) when using firebase

  15. 15

    Django: How to limit_choices_to when using custom intermediate table

  16. 16

    How to keep custom object sequence property in model when there are multiple lists of that type used in application

  17. 17

    Avoid showing UIAlertView when using PFLogInViewController

  18. 18

    How to avoid hardcode in every class WebClient retryWhen

  19. 19

    How to avoid warning about no return expression when using static_assert?

  20. 20

    How to avoid "Invalid byte sequence" when looking for link with text using Nokogiri

  21. 21

    How to avoid dropping items when using core.async pub/sub?

  22. 22

    How do I avoid absolute pathnames in my code when using Git?

  23. 23

    How to define an interface as a class property?

  24. 24

    Custom property delegation for arrays using a map

  25. 25

    Using custom property value to set a color in a template

  26. 26

    How to know when all Promises are Resolved in a dynamic "iterable" parameter?

  27. 27

    How do I get a property at index using custom validation in ASP.NET Core?

  28. 28

    How to access property of suggestions coming from my AutoSuggest ( custom made using .filter() )

  29. 29

    What is the nature of a class property when declared with "= {}()" in Swift?

ホットタグ

アーカイブ