ronantakizawa/codereview-bench huggingface dataset:
Repository: apple/swift
File: stdlib/public/Synchronization/Mutex/OpenBSDImpl.swift (Swift)

Code before:
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Glibc

@usableFromInline
@_transparent
func errstr(_ no: Int32) -> String {
  let a: [CChar] = unsafe Array(unsafeUninitializedCapacity: Int(NL_TEXTMAX)) {
    unsafe strerror_r(no, $0.baseAddress, $1)
  }
  return String(validatingUTF8: a) ?? ""
}

@available(SwiftStdlib 6.0, *)
@frozen
@_staticExclusiveOnly
@safe
public struct _MutexHandle: ~Copyable {
  @usableFromInline
  @safe
  let value: _Cell<pthread_mutex_t?>

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  public init() {
    var mx = unsafe pthread_mutex_t(bitPattern: 0)
    let r = unsafe pthread_mutex_init(&mx, nil)
    if r != 0 {
      fatalError("couldn't initialize mutex: \(errstr(errno))")
    }
    value = unsafe _Cell(mx)
  }

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient

Review comment (suggestion):
```suggestion
  unsafe withUnsafeTemporaryAllocation(of: CChar.self, capacity: Int(NL_TEXTMAX)) { buf in
    unsafe strerror_r(no, buf.baseAddress, buf.count)
    return String(validatingCString: buf.baseAddress)
      ?? "An unknown error occurred (\(no))."
  }
```


Code after:
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Glibc

@usableFromInline
@_transparent
func errstr(_ no: Int32) -> String {
  unsafe withUnsafeTemporaryAllocation(of: CChar.self, capacity: Int(NL_TEXTMAX)) { buf in
    unsafe strerror_r(no, buf.baseAddress!, buf.count)
    return unsafe String(validatingCString: buf.baseAddress!)
      ?? "An unknown error occurred (\(no))."
  }
}

@available(SwiftStdlib 6.0, *)
@frozen
@_staticExclusiveOnly
@safe
public struct _MutexHandle: ~Copyable {
  @usableFromInline
  @safe
  let value: _Cell<pthread_mutex_t?>

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  public init() {
    var mx = unsafe pthread_mutex_t(bitPattern: 0)
    let r = unsafe pthread_mutex_init(&mx, nil)
    if r != 0 {
      fatalError("couldn't initialize mutex: \(errstr(errno))")
    }
    value = unsafe _Cell(mx)
  }

  @available(SwiftStdlib 6.0, *)
Repository: apple/swift
File: stdlib/public/Synchronization/Mutex/OpenBSDImpl.swift (Swift)

Code before:
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Glibc

@available(SwiftStdlib 6.0, *)
@frozen
@_staticExclusiveOnly
public struct _MutexHandle: ~Copyable {
  @usableFromInline
  let value: _Cell<pthread_mutex_t?>

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  public init() {
    var mx = pthread_mutex_t(bitPattern: 0)
    pthread_mutex_init(&mx, nil)
    value = _Cell(mx)
  }

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  internal borrowing func _lock() {
    pthread_mutex_lock(value._address)
  }

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  internal borrowing func _tryLock() -> Bool {
    pthread_mutex_trylock(value._address) == 0

Review comment (suggestion):
Does the OpenBSD implementation call `strerror()` elsewhere? Not for this PR, but would be worth auditing the codebase and replacing such calls with something like this function in the future. (Same for FreeBSD.)

Code after:
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Glibc

@usableFromInline
@_transparent
func errstr(_ no: Int32) -> String {
  unsafe withUnsafeTemporaryAllocation(of: CChar.self, capacity: Int(NL_TEXTMAX)) { buf in
    unsafe strerror_r(no, buf.baseAddress!, buf.count)
    return unsafe String(validatingCString: buf.baseAddress!)
      ?? "An unknown error occurred (\(no))."
  }
}

@available(SwiftStdlib 6.0, *)
@frozen
@_staticExclusiveOnly
@safe
public struct _MutexHandle: ~Copyable {
  @usableFromInline
  @safe
  let value: _Cell<pthread_mutex_t?>

  @available(SwiftStdlib 6.0, *)
  @_alwaysEmitIntoClient
  @_transparent
  public init() {
    var mx = unsafe pthread_mutex_t(bitPattern: 0)
    let r = unsafe pthread_mutex_init(&mx, nil)
    if r != 0 {
      fatalError("couldn't initialize mutex: \(errstr(errno))")
    }
Repository: apple/swift
File: test/ModuleInterface/preconcurrency-deinit.swift (Swift)

Code before:
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -module-name SwiftLibrary -package-name SwiftLibraryPkg %t/SwiftLibrary.swift -emit-module -emit-module-interface-path %t/SwiftLibrary.swiftinterface -swift-version 6 -I %t/ObjCLibrary
// RUN: %FileCheck %s < %t/SwiftLibrary.swiftinterface

// CHECK-NOT: @preconcurrency isolated deinit

//--- SwiftLibrary.swift
import ObjCLibrary

public class SwiftSubclass: ObjCBaseClass {
    isolated deinit {}
}

//--- ObjCLibrary/module.modulemap
module ObjCLibrary {
  header "ObjCBaseClass.h"
  export *
}

//--- ObjCLibrary/ObjCBaseClass.h

#import <Foundation/Foundation.h>

__attribute__((__swift_attr__("@MainActor")))
@interface ObjCBaseClass : NSObject
@end


Review comment (suggestion):
`-package-name SwiftLibraryPkg` shouldn't be necessary

Code after:
// REQUIRES: objc_interop

// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -module-name SwiftLibrary %t/SwiftLibrary.swift -emit-module -emit-module-interface-path %t/SwiftLibrary.swiftinterface -swift-version 6 -I %t/ObjCLibrary -experimental-allow-module-with-compiler-errors
// Added experimental-allow-module-with-compiler-errors flag to avoid crashes on the assert in serialization
// RUN: %FileCheck %s < %t/SwiftLibrary.swiftinterface

//--- SwiftLibrary.swift
import ObjCLibrary

// CHECK: {{^ @objc isolated deinit$}}
public class SwiftSubclass: ObjCBaseClass {
    isolated deinit {}
}

//--- ObjCLibrary/module.modulemap
module ObjCLibrary {
  header "ObjCBaseClass.h"
  export *
}

//--- ObjCLibrary/ObjCBaseClass.h

#import <Foundation/Foundation.h>

__attribute__((__swift_attr__("@MainActor")))
@interface ObjCBaseClass : NSObject
@end
Repository: apple/swift
File: test/DebugInfo/modulecache.swift (Swift)

Code before:
// RUN: %empty-directory(%t)
// Clang-import a module.
import ClangModule

// Note: This test is highly dependent on the clang module cache
// format, but it is testing specifics of the module cache.

// 1. Test that swift-ide-test creates a thin module without debug info.

// RUN: %empty-directory(%t)
// RUN: %swift-ide-test_plain -print-usrs -target %target-triple -module-cache-path %t  -I %S/Inputs -source-filename %s
// RUN: dd bs=1 count=4 < %t/*/ClangModule-*.pcm 2>/dev/null | grep -q CPCH

// 2. Test that swift is creating clang modules with debug info.

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -c -g -o %t.o -module-cache-path %t -I %S/Inputs
// RUN: llvm-readobj -h %t/*/ClangModule-*.pcm | %FileCheck %s
// CHECK: Format: {{(Mach-O|ELF|elf64|COFF|elf32-littlearm|WASM)}}

// 3. Test that swift-ide-check will not share swiftc's module cache.

// RUN: %swift-ide-test_plain -print-usrs -target %target-triple -module-cache-path %t  -I %S/Inputs -source-filename %s


Review comment (suggestion):
@hamishknight this change should not have any negative impact I hope? `_plain` variant doesn't pass required resource dir options necessary for cross-compilation.

Code after:
// RUN: %empty-directory(%t)
// Clang-import a module.
import ClangModule

// Note: This test is highly dependent on the clang module cache
// format, but it is testing specifics of the module cache.

// 1. Test that swift-ide-test creates a thin module without debug info.

// RUN: %empty-directory(%t)
// RUN: %swift-ide-test -print-usrs -target %target-triple -module-cache-path %t  -I %S/Inputs -source-filename %s
// RUN: dd bs=1 count=4 < %t/*/ClangModule-*.pcm 2>/dev/null | grep -q CPCH

// 2. Test that swift is creating clang modules with debug info.

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -c -g -o %t.o -module-cache-path %t -I %S/Inputs
// RUN: llvm-readobj -h %t/*/ClangModule-*.pcm | %FileCheck %s
// CHECK: Format: {{(Mach-O|ELF|elf64|COFF|elf32-littlearm|WASM)}}

// 3. Test that swift-ide-check will not share swiftc's module cache.

// RUN: %swift-ide-test -print-usrs -target %target-triple -module-cache-path %t  -I %S/Inputs -source-filename %s
Repository: apple/swift
File: SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyStructExtract.swift (Swift)

Code before:
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import SIL

private extension Value {
  var lookThroughMarkDependenceNonEscapingInstructions: Value {
    if let mdi = self as? MarkDependenceInst, mdi.isNonEscaping {
      return mdi.value.lookThroughMarkDependenceNonEscapingInstructions
    }
    return self
  }
}

extension StructExtractInst : OnoneSimplifiable {
  func simplify(_ context: SimplifyContext) {
    var operand = self.struct
    if (self.ownership == .none) {
      operand = self.struct.lookThroughMarkDependenceNonEscapingInstructions
    }
    guard let structInst = operand as? StructInst else {
      return
    }
    context.tryReplaceRedundantInstructionPair(first: structInst, second: self,
                                               with: structInst.operands[fieldIndex].value)
  }
}


Review comment (refactor):
Why does this only work with none ownership? It should also work for "guaranteed", no?
Note that "owned" is not possible because `struct_extract` requires "none" or "guaranteed".

If it has a good reason, please add a comment.

BTW, you don't need parentheses.

Code after:
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import SIL

private extension Value {
  var lookThroughMarkDependenceInstructions: Value {
    if let mdi = self as? MarkDependenceInst {
      return mdi.value.lookThroughMarkDependenceInstructions
    }
    return self
  }
}

extension StructExtractInst : OnoneSimplifiable {
  func simplify(_ context: SimplifyContext) {
    let operand = self.struct.lookThroughMarkDependenceInstructions
    guard let structInst = operand as? StructInst else {
      return
    }
    context.tryReplaceRedundantInstructionPair(first: structInst, second: self,
                                               with: structInst.operands[fieldIndex].value)
  }
}
Repository: apple/swift
File: validation-test/Sema/type_checker_perf/slow/leading_dot_delay.swift (Swift)

Code before:
// RUN: %target-typecheck-verify-swift -solver-scope-threshold=100

// https://forums.swift.org/t/typechecker-performance-is-way-worse-in-6-3/84779

struct NSColor: Equatable {
  init(red: Double, green: Double, blue: Double, alpha: Double) {}
}

var backgroundColor: NSColor?

func XCTAssertEqual<T: Equatable>(_: T, _: T) {}

func test() {
  XCTAssertEqual(backgroundColor, .init(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, .init(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))  // expected-error {{reasonable time}}
  XCTAssertEqual(backgroundColor, NSColor(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, NSColor(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))
}


Review comment (suggestion):
Let's add `NSColor.init` for completeness here as well since the initializer references are modeled slightly differently.

Code after:
// RUN: %target-typecheck-verify-swift -solver-scope-threshold=100

// https://forums.swift.org/t/typechecker-performance-is-way-worse-in-6-3/84779

class NSColor: Equatable {
  init(red: Double, green: Double, blue: Double, alpha: Double) {}

  static func ==(_: NSColor, _: NSColor) -> Bool { return false }
}

var backgroundColor: NSColor
var optBackgroundColor: NSColor?

func XCTAssertEqual<T: Equatable>(_: T, _: T) {}

func test() {
  XCTAssertEqual(backgroundColor, .init(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, .init(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))  // expected-error {{reasonable time}}
  XCTAssertEqual(backgroundColor, NSColor(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, NSColor(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, NSColor.init(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(backgroundColor, NSColor.init(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))

  XCTAssertEqual(optBackgroundColor, .init(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(optBackgroundColor, .init(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))  // expected-error {{reasonable time}}
  XCTAssertEqual(optBackgroundColor, NSColor(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(optBackgroundColor, NSColor(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))
  XCTAssertEqual(optBackgroundColor, NSColor.init(red: 244.0 / 255.0, green: 218.0 / 255.0, blue: 129.0 / 255.0, alpha: 1.0))
  XCTAssertEqual(optBackgroundColor, NSColor.init(red: 244 / 255.0, green: 218 / 255.0, blue: 129 / 255.0, alpha: 1.0))
}
Repository: apple/swift
File: test/Constraints/issue-87300.swift (Swift)

Code before:
// RUN: %target-typecheck-verify-swift

// https://github.com/swiftlang/swift/issues/87300

func f(_ t: Any) -> Int {}
func f(_ t: AnyClass) -> String {}

class T {}

let result = f(T.self)
let expect: String = result


Review comment (performance):
Please add a test-case where the parameter is labeled as well just case cause because single parameter with and without label are handled differently in the optimizer sometimes.

Code after:
// RUN: %target-typecheck-verify-swift

// https://github.com/swiftlang/swift/issues/87300

func f(_ t: Any) -> Int {}
func f(_ t: AnyClass) -> String {}

func f(t: Any) -> Int {}
func f(t: AnyClass) -> String {}

class T {}

do {
  let result = f(T.self)
  let _: String = result
}

struct S: ~Copyable {}

do {
  let result = f(S.self)
  let _: Int = result
}

do {
  let result = f(t: S.self)
  let _: Int = result
}
Repository: apple/swift
File: test/Interop/Cxx/foreign-reference/incomplete.swift (Swift)

Code before:
    // CHECK: Incomplete weight = 3.14159
    print("Incomplete weight = \(i.weight)")

    // Instance destroyed at the end
  }

  // CHECK: Destroyed instance containing weight 3.14159
}

func testOpaqueRef() {
  // CHECK: Creating OpaqueRef
  print("Creating OpaqueRef")
  let opaque = Opaque_create()
  let opaque2 = opaque
  _ = opaque
  _ = opaque2
  // let it go out of scope

  // CHECK: Destroyed OpaqueRef instance
}

struct HasOpaqueRef { var mine: OpaqueRef }

func testOpaqueRefInStruct() {
  var cat : HasOpaqueRef? = nil;
	cat = HasOpaqueRef(mine: Opaque_create())
  // CHECK: Destroyed OpaqueRef instance
  // CHECK-NOT: Destroyed OpaqueRef instance
}

testIncomplete()
testOpaqueRef()
testOpaqueRefInStruct()

// CHECK: DONE
print("DONE")


Review comment (suggestion):
Nit:
```suggestion
  var cat : HasOpaqueRef? = nil
  cat = HasOpaqueRef(mine: Opaque_create())
```

Code after:
    // CHECK: Incomplete weight = 3.14159
    print("Incomplete weight = \(i.weight)")

    // Instance destroyed at the end
  }

  // CHECK: Destroyed instance containing weight 3.14159
}

func testOpaqueRef() {
  // CHECK: Creating OpaqueRef
  print("Creating OpaqueRef")
  let opaque = Opaque_create()
  let opaque2 = opaque
  _ = opaque
  _ = opaque2
  // let it go out of scope

  // CHECK: Destroyed OpaqueRef instance
}

struct HasOpaqueRef { var mine: OpaqueRef }

func testOpaqueRefInStruct() {
  var cat : HasOpaqueRef? = nil
  cat = HasOpaqueRef(mine: Opaque_create())
  // CHECK: Destroyed OpaqueRef instance
  // CHECK-NOT: Destroyed OpaqueRef instance
}

testIncomplete()
testOpaqueRef()
testOpaqueRefInStruct()

// CHECK: DONE
print("DONE")
Repository: apple/swift
File: validation-test/SILOptimizer/gh87462.swift (Swift)

Code before:
// RUN: %target-swift-frontend -target %target-swift-5.5-abi-triple -parse-as-library -c -O %s

// REQUIRES: VENDOR=apple

@available(macOS 15.4, *)
actor Bar<T> {
  isolated deinit {}
}

@MainActor
final class Foo<T> {
  isolated deinit {}
}


Review comment (suggestion):
Might be better to use `@available(SwiftStdlib 6.1, *)` here to cover all of the Swift 6.1-era OSes.
```suggestion
@available(SwiftStdlib 6.1, *)
```

Code after:
// RUN: %target-swift-frontend -target %target-swift-5.5-abi-triple -parse-as-library -c -O %s

// REQUIRES: VENDOR=apple

@available(SwiftStdlib 6.1, *)
actor Bar<T> {
  isolated deinit {}
}

@MainActor
final class Foo<T> {
  isolated deinit {}
}
Repository: benbusby/whoogle-search
File: app/filter.py (Python)

Code before:
from app.request import VALID_PARAMS, MAPS_URL
from app.utils.results import *
from bs4 import BeautifulSoup
from bs4.element import ResultSet, Tag
from cryptography.fernet import Fernet
from flask import render_template
import re
import urllib.parse as urlparse
from urllib.parse import parse_qs
import os


def extract_q(q_str: str, href: str) -> str:
    """Extracts the 'q' element from a result link. This is typically
    either the link to a result's website, or a string.

    Args:
        q_str: The result link to parse
        href: The full url to check for standalone 'q' elements first,
              rather than parsing the whole query string and then checking.

    Returns:
        str: The 'q' element of the link, or an empty string
    """
    return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''


def clean_query(query: str) -> str:
    """Strips the blocked site list from the query, if one is being
    used.

    Args:
        query: The query string

    Returns:

Review comment (suggestion):
You'll need to import `read_config_bool` now that you're using it here

```suggestion
import os
from app.utils.misc import read_config_bool
```

Code after:
from app.request import VALID_PARAMS, MAPS_URL
from app.utils.results import *
from bs4 import BeautifulSoup
from bs4.element import ResultSet, Tag
from cryptography.fernet import Fernet
from flask import render_template
import re
import urllib.parse as urlparse
from urllib.parse import parse_qs
import os
from app.utils.misc import read_config_bool


def extract_q(q_str: str, href: str) -> str:
    """Extracts the 'q' element from a result link. This is typically
    either the link to a result's website, or a string.

    Args:
        q_str: The result link to parse
        href: The full url to check for standalone 'q' elements first,
              rather than parsing the whole query string and then checking.

    Returns:
        str: The 'q' element of the link, or an empty string
    """
    return parse_qs(q_str)['q'][0] if ('&q=' in href or '?q=' in href) else ''


def clean_query(query: str) -> str:
    """Strips the blocked site list from the query, if one is being
    used.

    Args:
        query: The query string
Repository: benbusby/whoogle-search
File: app/utils/results.py (Python)

Code before:
from bs4 import BeautifulSoup
import os
import urllib.parse as urlparse
from urllib.parse import parse_qs
import re


SKIP_ARGS = ['ref_src', 'utm']
SKIP_PREFIX = ['//www.', '//mobile.', '//m.']
GOOG_STATIC = 'www.gstatic.com'
GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo'
LOGO_URL = GOOG_IMG + '_desk'
BLANK_B64 = ('data:image/png;base64,'
             'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkw'
             'AIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC')


# Ad keywords
BLACKLIST = [
    'ad', 'anuncio', 'annuncio', 'annonce', 'Anzeige', '广告', '廣告', 'Reklama',
    'Реклама', 'Anunț', '광고', 'annons', 'Annonse', 'Iklan', '広告', 'Augl.',
    'Mainos', 'Advertentie', 'إعلان', 'Գովազդ', 'विज्ञापन', 'Reklam', 'آگهی',
    'Reklāma', 'Reklaam', 'Διαφήμιση', 'מודעה', 'Hirdetés', 'Anúncio'
]

SITE_ALTS = {
    'twitter.com': os.getenv('WHOOGLE_ALT_TW', 'nitter.net'),
    'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
    'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),
    'reddit.com': os.getenv('WHOOGLE_ALT_RD', 'libredd.it'),

Review comment (suggestion):
Needs `NavigableString` import since it's being used in `bold_search_terms` now

```suggestion
import re
from bs4 import NavigableString
```

Code after:
from bs4 import BeautifulSoup
import os
import urllib.parse as urlparse
from urllib.parse import parse_qs
import re
from bs4 import NavigableString


SKIP_ARGS = ['ref_src', 'utm']
SKIP_PREFIX = ['//www.', '//mobile.', '//m.']
GOOG_STATIC = 'www.gstatic.com'
GOOG_IMG = '/images/branding/searchlogo/1x/googlelogo'
LOGO_URL = GOOG_IMG + '_desk'
BLANK_B64 = ('data:image/png;base64,'
             'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAQAAAAnOwc2AAAAD0lEQVR42mNkw'
             'AIYh7IgAAVVAAuInjI5AAAAAElFTkSuQmCC')


# Ad keywords
BLACKLIST = [
    'ad', 'anuncio', 'annuncio', 'annonce', 'Anzeige', '广告', '廣告', 'Reklama',
    'Реклама', 'Anunț', '광고', 'annons', 'Annonse', 'Iklan', '広告', 'Augl.',
    'Mainos', 'Advertentie', 'إعلان', 'Գովազդ', 'विज्ञापन', 'Reklam', 'آگهی',
    'Reklāma', 'Reklaam', 'Διαφήμιση', 'מודעה', 'Hirdetés', 'Anúncio'
]

SITE_ALTS = {
    'twitter.com': os.getenv('WHOOGLE_ALT_TW', 'nitter.net'),
    'youtube.com': os.getenv('WHOOGLE_ALT_YT', 'invidious.snopyta.org'),
    'instagram.com': os.getenv('WHOOGLE_ALT_IG', 'bibliogram.art/u'),