asottile / pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

some way to skip replacing mock with unittest.mock

graingert opened this issue · comments

when you're using python 3.6 or 3.7 unittest.mock.AsyncMock is unavailable, but mock.AsyncMock is available if you're using the latest backport

there should be some way to skip replacing mock with unittest.mock, or the fixer should be moved to --py38-plus and then to a later --py...-plus as and when unittest.mock gains features

@mxr ^ thoughts

commented

I suppose we could hardcode of a list of unittest.mock attrs and the version they were added into unittest.mock, and rewrite conditionally based on that

maybe --no-mock is easier, idk

commented

But would you want --no-xx for suppressing an arbitrary rewrite? If not, why this specific case?

only this case because there's a good reason to keep it (%-rewrite could break python2 in some exotic scenarios) -- unless we can actually detect it properly and then we don't need an option

commented

It should be possible to detect it properly using the approach I outlined

also mock.patch behaves differently (on 3.6/3.7 Vs pypi mock/3.8) when applied to a coroutinefunction

Also I don't like an autodetect because I don't want some project files using unittest.mock and others using mock

thirdly how should other backports be handled? eg functools32 contextlib2 pkg_util_resolve_name etc?

commented

Good points, sounds like --no-mock is the best approach for now