Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives (no-name-in-module) and (not-context-manager) #1542

Closed
ReDeiPirati opened this issue Jun 17, 2017 · 8 comments
Closed

False positives (no-name-in-module) and (not-context-manager) #1542

ReDeiPirati opened this issue Jun 17, 2017 · 8 comments

Comments

@ReDeiPirati
Copy link

ReDeiPirati commented Jun 17, 2017

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 :)

@rogalski
Copy link
Contributor

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.

@ReDeiPirati
Copy link
Author

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

@huan
Copy link

huan commented Jul 28, 2017

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!

@rogalski
Copy link
Contributor

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

@huan
Copy link

huan commented Sep 6, 2017

@rogalski Thank you very much!

huan added a commit to huan/node-facenet that referenced this issue Sep 6, 2017
@CNugteren
Copy link

CNugteren commented Sep 27, 2017

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)

@Heba-a1
Copy link

Heba-a1 commented Apr 19, 2020

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

@PCManticore
Copy link
Contributor

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.

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

No branches or pull requests

6 participants