add tag
Pax
I want to replace the `query` of a `ParseResult` (which is a named tuple) but if I use `._replace()` Pylance will complain `"_replace" is protected and used outside of the class in which it is declared`

Ignoring Pylance is not an option. A solution I can think of:

```
ParseResult(
   scheme=link.scheme,
   netloc=link.netloc,
   path=link.path,
   params=link.params,
   query="utm_source=newsource&utm_medium=newmedium",
   fragment=link.fragment,
)
```

Is this the best way to do this? Or am I missing some Python idiom?
Top Answer
wizzwizz4
Pylance is wrong. Bypass it.

```python
replace = getattr(ParseResult, '_replace')
replace(link, query="utm_source=newsource&utm_medium=newmedium")
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.