This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author andrei.avk
Recipients andrei.avk, lukasz.langa
Date 2021-09-22.02:09:51
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632276592.19.0.282497085122.issue45215@roundup.psfhosted.org>
In-reply-to
Content
Łukasz:

For parent, there's this issue: #39222 (which is why I started looking into this).

For name, I couldn't find anything here or on SO, but it's hard to search for this because keywords 'mock argument name' on SO finds over 700 results but they're referring to argument names, rather than literal argument `name`. I didn't look through all 700 though :)

The scenario that I was thinking about that could cause issues is that one developer creates a bunch of tests with Mock(name=1) for example, that doesn't cause any issues if the mocks aren't printed (for example if they're attributes). Some time later another dev is expanding or debugging the tests and needs to print the mocks, which causes errors. Now the 2nd dev will need to figure out why the first dev used these names and if they can be safely changed to strings - quite annoying.

It seems like the instances in the std lib of name args are of the form:

init(name)
 self.name = name

repr()
 return '<... %s ...>' % self.name

or equivalent; I've also did a grep for `return self.name` and it was a fairly short list so i was able to check all of them, and all of the hits either internal use classes or functions, or check the type of `name` in __init__, or the return is not from __repr__ but from some other function.

I didn't check all instances of where name arg is passed to init, because it's a much longer list and I figured the cases where it could be a problem would be ones with `__repr__(): return self.name`, and those are all fine.

The case with Mock is also different because users are not passing it as a known argument but as a "mock accepts all arguments and sets them as attrs" type of usage.

On the other hand, I don't think this is a high priority issue, users are probably not using name and parent args that often, and when they do, most of them probably try to print them as they work on the test; and if they do run into this issue later, it's not very hard to fix.

So it might be worth just leaving this open and seeing if more users run into it.

Let me know what you think!
History
Date User Action Args
2021-09-22 02:09:52andrei.avksetrecipients: + andrei.avk, lukasz.langa
2021-09-22 02:09:52andrei.avksetmessageid: <1632276592.19.0.282497085122.issue45215@roundup.psfhosted.org>
2021-09-22 02:09:52andrei.avklinkissue45215 messages
2021-09-22 02:09:51andrei.avkcreate