[issue43478] Disallow Mock spec arguments from being Mocks

2022-02-02 Thread Matthew Suozzo
Change by Matthew Suozzo : -- pull_requests: +29275 pull_request: https://github.com/python/cpython/pull/31090 ___ Python tracker <https://bugs.python.org/issue43

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2021-04-11 Thread Matthew Suozzo
Change by Matthew Suozzo : -- pull_requests: +24081 stage: needs patch -> patch review pull_request: https://github.com/python/cpython/pull/25347 ___ Python tracker <https://bugs.python.org/issu

[issue37251] Mocking a MagicMock with a function spec results in an AsyncMock

2021-04-09 Thread Matthew Suozzo
Matthew Suozzo added the comment: I don't think this was actually fixed for the create_autospec case. create_autospec still uses the only is_async_func check to enable use of AsyncMock and that still does a __code__ check. There was a test submitted to check this case but the test itself

[issue43478] Disallow Mock spec arguments from being Mocks

2021-04-09 Thread Matthew Suozzo
Change by Matthew Suozzo : -- keywords: +patch nosy: +matthew.suozzo nosy_count: 7.0 -> 8.0 pull_requests: +24061 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25326 ___ Python tracker <https://bugs.p

[issue43798] Add position metadata to alias AST type

2021-04-09 Thread Matthew Suozzo
Matthew Suozzo added the comment: Ah and one other question: Is this normally the sort of thing that would get backported? It should be very straightforward to do so, at least for 3.9 given the support for the new parser. -- versions: -Python 3.6, Python 3.7, Python 3.8

[issue43798] Add position metadata to alias AST type

2021-04-09 Thread Matthew Suozzo
Change by Matthew Suozzo : -- keywords: +patch pull_requests: +24059 stage: -> patch review pull_request: https://github.com/python/cpython/pull/25324 ___ Python tracker <https://bugs.python.org/issu

[issue43798] Add position metadata to alias AST type

2021-04-09 Thread Matthew Suozzo
New submission from Matthew Suozzo : Given the increasing use of long `from typing import foo, bar, ...` import sequences, it's becoming more desirable to address individual components of the import node. Unfortunately, the ast.alias node doesn't contain source location metadata (e.g. lineno

[issue43478] Disallow Mock spec arguments from being Mocks

2021-03-16 Thread Matthew Suozzo
Matthew Suozzo added the comment: And to give some context for the above autospec child bit, this is the relevant code that determines the spec to use for each child: https://github.com/python/cpython/blob/master/Lib/unittest/mock.py#L2671-L2696

[issue43478] Disallow Mock spec arguments from being Mocks

2021-03-16 Thread Matthew Suozzo
Matthew Suozzo added the comment: A few more things: Assertions on Mock-autospec'ed Mocks will silently pass since e.g. assert_called_once_with will now be mocked out. This may justify a more stringent stance on the pattern since it risks hiding real test failures. One complicating factor

[issue43478] Disallow Mock spec arguments from being Mocks

2021-03-15 Thread Matthew Suozzo
Matthew Suozzo added the comment: I've fixed a bunch of these in our internal repo so I'd be happy to add that to a patch implementing raising exceptions for these cases. -- ___ Python tracker <https://bugs.python.org/issue43

[issue43478] Disallow Mock spec arguments from being Mocks

2021-03-11 Thread Matthew Suozzo
New submission from Matthew Suozzo : An unfortunately common pattern over large codebases of Python tests is for spec'd Mock instances to be provided with Mock objects as their specs. This gives the false sense that a spec constraint is being applied when, in fact, nothing will be disallowed

[issue42551] Generator `yield`s counted as primitive calls by cProfile

2020-12-14 Thread Matthew Suozzo
Matthew Suozzo added the comment: One of the problems with my proposed solution that I glossed over was how and where to count the primitive call. If the primitive call is only registered on RETURN (i.e. after all yields), a generator that is incompletely exhausted would have 0 primitive

[issue42551] Generator `yield`s counted as primitive calls by cProfile

2020-12-02 Thread Matthew Suozzo
New submission from Matthew Suozzo : # Issue When profiling a generator function, the initial call and all subsequent yields are aggregated into the same "ncalls" metric by cProfile. ## Example >>> cProfile.run(""" ... def foo(): ... yield 1 ... yield

[issue42353] Proposal: re.prefixmatch method (alias for re.match)

2020-11-14 Thread Matthew Suozzo
Matthew Suozzo added the comment: > It just won't work unless you add explicit ".*" or ".*?" at the start of the > pattern But think of when regexes are used for validating input. Getting it to "just work" may be over-permissive validation tha