Re-export ._replace
as .replace
in urllib.parse
result types
#136083
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I do Python interviewing, and part of one of our interviews has folks parsing URLs.
I've noticed people gloss over the
._replace
at the end of the examples in https://docs.python.org/3/library/urllib.parse.html#urllib.parse.urlparse and I'm somewhat convinced that's due to the fact that subconsciously PEP 8 (and beyond) has trained folks to assume leading underscore is not "public" ( a good convention).This isn't a debate about
namedtuple
. I assume it uses._replace
so that it doesn't preclude folks from usingnamedtuple
with a field namedreplace
.But for concrete
namedtuple
subclasses which are known not to have areplace
field, it'd be nice if the callers could just use.replace
like all the other "normal" classes.(Then there's the issue with linters complaining about usage of using a method that starts with an underscore, but that's not my motivation so I'll just point it out and move on)
(I also don't want this to devolve into a conversation about "ok but what about ". Perfect is the enemy og good)