openai / openai/tiktoken

CoreBPE::new has an unconstrained NSE type parameter, making normal downstream calls fail type inference

Open Beginner friendly
#557 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
19.3k
Forks
1.6k
PR merge metrics
No merged PRs in 30d

Description

Verified on current main at 08a5f3b (May 24, 2026).

CoreBPE::new currently has this signature in src/lib.rs:

pub fn new<E, SE, NSE>(
    encoder: E,
    special_tokens_encoder: SE,
    pattern: &str,
) -> Result<Self, Box<dyn std::error::Error + Send + Sync>>
where
    E: IntoIterator<Item = (Vec<u8>, Rank)>,
    SE: IntoIterator<Item = (String, Rank)>,
    NSE: IntoIterator<Item = (String, (Rank, Rank))>,

The NSE type parameter is not used in the function arguments or return type, so normal downstream calls cannot infer it.

Minimal repro from an external crate:

use tiktoken::{CoreBPE, Rank};

fn main() {
    let _ = CoreBPE::new(
        vec![(b"a".to_vec(), 0 as Rank)],
        Vec::<(String, Rank)>::new(),
        r".",
    );
}

cargo check fails with:

error[E0283]: type annotations needed
 --> src/main.rs:4:13
  |
4 |     let _ = CoreBPE::new(
  |             ^^^^^^^^^^^^ cannot infer type of the type parameter `NSE` declared on the associated function `new`

This seems like a real public Rust API bug rather than an internal-only issue, since Cargo.toml publishes an rlib in addition to the Python extension.

Expected behavior:

  • A normal downstream call to CoreBPE::new(...) should compile without requiring unrelated generic annotations.

Likely fix:

  • Remove the unused NSE type parameter from CoreBPE::new.

Thanks!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/lib.rs at the CoreBPE::new signature and inspect the external-crate reproduction from the issue. Remove the unused generic constraint, then run cargo check with the shown CoreBPE::new call; done means normal downstream calls compile without unrelated type annotations.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.