Pylint: False positives (no-name-in-module) and (not-context-manager)

Created on 17 Jun 2017  路  8Comments  路  Source: PyCQA/pylint

Steps to reproduce

  1. git clone https://github.com/ReDeiPirati/seq2seq.git && cd seq2seq
  2. pylint -E seq2seq

[Optional] If you want to run a full coverage test pipeline: pip install -e . && pip install nose pylint tox yapf mkdocs && tox

Current behavior

Same behavior for both python2.7 and python3.5

************* Module seq2seq.losses
E: 37, 2: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.test.bridges_test
E: 73, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.test.rnn_cell_test
E: 38, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 62, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 77, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 84, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 90, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 98, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:113, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:120, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:127, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:135, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.data.sequence_example_decoder
E: 17, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.data.input_pipeline
E: 32, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.data.split_tokens_decoder
E: 24, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.data.parallel_data_provider
E: 25, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
E: 26, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.training.utils
E:259, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.tasks.dump_attention
E: 26, 0: Unable to import 'matplotlib' (import-error)
************* Module seq2seq.encoders.conv_encoder
E: 87, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:101, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.encoders.image_encoder
E: 23, 0: No name 'slim' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.encoders.rnn_encoder
E: 24, 0: No name 'rnn' in module 'LazyLoader' (no-name-in-module)
************* Module seq2seq.contrib.rnn_cell
E: 80, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E: 97, 8: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.metrics.metric_specs
E: 31, 0: No name 'learn' in module 'LazyLoader' (no-name-in-module)
E:107, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
************* Module seq2seq.models.model_base
E:144, 4: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)
E:145, 6: Context manager 'generator' doesn't implement __enter__ and __exit__. (not-context-manager)

Similar: #613 not-context-manager #1524 #1536 no-name-in-module.
The not-context-manager error is a false positive because in the TensorFlow package(where the context-mager is coded) is actually well defined: look at tf_contextlib and tf_decorator.
Unfortunately i cannot explain why LazyLoader has triggered those errors, but the program works fine.

Expected behavior

No errors

pylint --version output

pylint with Python2

pylint 1.7.1, 
astroid 1.5.3
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609]

pylint with Python3

__main__.py 1.7.1, 
astroid 1.5.3
Python 3.5.3 (default, Jun 17 2017, 11:03:33) 
[GCC 4.9.2]

Thank you for you help and support :)

bug wont fix

Most helpful comment

For those also having this problem: I had to add the following in order to make it work:

contextmanager-decorators=contextlib.contextmanager,tensorflow.python.util.tf_contextlib.contextmanager

(note the extra tensorflow.python.util)

All 8 comments

not-context-manager can be easily tweaked by adding tf_contextlib.contextmanager to contextmanager-decorators value in settings.

LazyLoader is tricky abstraction around standard Python modules, which may need some hand-crafted solution so inference engine can resolve it to module itself and not this abstraction.

Thanks @rogalski. Indeed we have applied your suggestion as workaround for the contextmanager.

I ran into this issue today.

Could you please make the solution more clear, like where can I adding tf_contextlib.contextmanager to contextmanager-decorators value in settings?

Thanks!

@zixia simply run pylint --contextmanager-decorators=contextlib.contextmanager, tf_contextlib.contextmanager my_package or generate your own settings file.

@rogalski Thank you very much!

For those also having this problem: I had to add the following in order to make it work:

contextmanager-decorators=contextlib.contextmanager,tensorflow.python.util.tf_contextlib.contextmanager

(note the extra tensorflow.python.util)

No name 'slim' in module 'LazyLoader'
i have this error but cannot find solution ??

Given their use of LazyLoader I doubt there's too much we can do on pylint's side: https://github.com/tensorflow/tensorflow/blob/e4296aefff97e6edd3d7cee9a09b9dd77da4c034/tensorflow/python/util/lazy_loader.py
This is simply not feasible for a static analysis tool.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pylint-bot picture pylint-bot  路  3Comments

TBoshoven picture TBoshoven  路  3Comments

glmdgrielson picture glmdgrielson  路  3Comments

sambarluc picture sambarluc  路  3Comments

DGalt picture DGalt  路  3Comments