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

wrongly analysis of with statement by "target" type #2859

Closed
crackevil opened this issue Apr 9, 2019 · 0 comments
Closed

wrongly analysis of with statement by "target" type #2859

crackevil opened this issue Apr 9, 2019 · 0 comments

Comments

@crackevil
Copy link

crackevil commented Apr 9, 2019

Steps to reproduce

  1. have a context manager class, whose enter returns another object rather than "self"
  2. write with statement by that class's constructor
  3. pylint will warns "no member" error due to it assume "target" is a context manager class
    instance but in fact it was returned by context's enter method

sample code


class client_log(object):
	def __init__(self, client):
		self.client = client

	def __enter__(self):
		return self.client

	def __exit__(self, exc_type, exc_value, traceback):
		logger.info(self.client.get_log())

with client_log(client) as c:
	return c.foo()    **# pylint assume c is a client_log instance but c is a client instance**

pylint --version output

No config file found, using default configuration
pylint 1.9.4,
astroid 1.6.2
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]

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

No branches or pull requests

1 participant