Access to a protected member #12046
Replies: 2 comments 3 replies
-
Pytest code has a long history, and such conventions are not always followed. It's generally true that everything with underscore is private, but the inverse is not true. The official public parts of pytest is what's specified in the API reference: https://docs.pytest.org/en/stable/reference/reference.html |
Beta Was this translation helpful? Give feedback.
-
In that case I'm wondering why use underscores after all? Why not make it all 'public/without underscores' when it's not code but API reference that tells what's public and private? Don't get me wrong I understand there are legacy parts no one wants to change. I'm just trying to understand the logic behind it. I've seen similar code in urllib3, logging or django and at the moment I have no clue if that's state of the art or rather "not expected but accepted". The whole (non)public idea seems to be mixed up. Reading PEP8 I feel that the 'internal use' refers not to where given element is defined and used but to who (framework developer / end-user) defines and uses it. Am I correct? |
Beta Was this translation helpful? Give feedback.
-
Description:
Developing frameworks (like pytest) is challenging. There are probably different APIs you'd like to expose to end-user, plugin developers and different API you'd like to use for internal purposes. From my understanding (please, correct me if I'm wrong) pytest uses underscore to different what belongs to pytest-team and what's safe to use by rest of the world (end-users/plugin-developers).
PEP8 describes a single underscore (among others) as an "internal use" marker.

Not defining what the internal means exactly (project, class, specific scope).
Pylint definition is probably the most popular one

Question:
Are the following fragments of code phytonic?
Beta Was this translation helpful? Give feedback.
All reactions