Skip to content

fix(mypy): fix type: ignore placement for OTEL LogRecord import#20351

Merged
krrishdholakia merged 281 commits intoBerriAI:litellm_oss_staging_01_24_2026from
jquinter:fix/mypy-otel-logrecord-import
Feb 5, 2026
Merged

fix(mypy): fix type: ignore placement for OTEL LogRecord import#20351
krrishdholakia merged 281 commits intoBerriAI:litellm_oss_staging_01_24_2026from
jquinter:fix/mypy-otel-logrecord-import

Conversation

@jquinter
Copy link
Contributor

@jquinter jquinter commented Feb 3, 2026

Summary

  • Fix mypy attr-defined error on opentelemetry.py:1013 caused by # type: ignore being placed on the wrong line in a multi-line import
  • Collapse multi-line imports to single-line so # type: ignore[attr-defined] is on the from line where mypy reports the error
  • Add no-redef to the fallback except ImportError branch since SdkLogRecord is already defined in the try branch

Type

🐛 Bug Fix

Test plan

  • cd litellm && poetry run mypy . passes with 0 errors (1657 source files)

Changes

  • No functional change — only type-ignore comment placement

yuneng-jiang and others added 30 commits January 23, 2026 17:36
fix: ensure guardrail patterns persist on edit and mode toggle
[Fix] UI - Redirect to ui/login on expired JWT
…n Info panels (BerriAI#19688)

* ui for policy mgmt

* test_add_guardrails_from_policy_engine_accepts_dynamic_policies_and_pops_from_data
…19592)

Google announced that Gemini 2.0 Flash and Flash Lite models will be discontinued on March 31, 2026. Updated deprecation_date field for all affected model variants across different providers (vertex_ai, gemini, deepinfra, openrouter, vercel_ai_gateway).

Models updated:
- gemini-2.0-flash (added deprecation date)
- gemini-2.0-flash-001 (updated from 2026-02-05)
- gemini-2.0-flash-lite (added deprecation date)
- gemini-2.0-flash-lite-001 (updated from 2026-02-25)

All variants now correctly reflect the March 31, 2026 shutdown date.
[Fix] Team Update with Organization having All Proxy Models
…odel

[Feature] UI - Organization Edit Page: Reusable Model Select
yuneng-jiang and others added 20 commits January 28, 2026 20:29
…_usage_report

[Feature] UI - Usage Export: Breakdown by Teams and Keys
Add test to check if model map is corretly formatted
…el_map_entry

Fix: litellm_fix_robotic_model_map_entry
…_llm_provider2

Add custom_llm_provider as gemini translation
…orting_fix

[Fix] Sorting for /v2/model/info
The type: ignore[attr-defined] comment was on the import alias line
inside parentheses, but mypy reports the error on the `from` line.
Collapse to single-line imports so the suppression is on the correct
line. Also add no-redef to the fallback branch.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Feb 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Error Error Feb 3, 2026 5:34pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 3, 2026

Greptile Overview

Greptile Summary

Fixed mypy type checking errors by correcting the placement of # type: ignore comments in the OpenTelemetry integration.

Changes:

  • Collapsed multi-line imports to single-line format for both the try and except branches of LogRecord import
  • Moved # type: ignore[attr-defined] to the from line (1007) where mypy actually reports the error
  • Added no-redef suppression to the fallback import (1009) since SdkLogRecord is defined in both branches

Impact:

  • No functional changes to runtime behavior
  • Resolves mypy attr-defined errors that were previously reported on line 1013
  • Improves type checking accuracy for both OTEL SDK versions (< 1.39.0 and >= 1.39.0)

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • Only affects type checking comments with no runtime changes; fixes legitimate mypy errors by following best practices for type ignore placement on single-line imports
  • No files require special attention

Important Files Changed

Filename Overview
litellm/integrations/opentelemetry.py Collapsed multi-line imports to single-line and moved mypy type ignore comments to correct position; added no-redef suppression for fallback import

Sequence Diagram

sequenceDiagram
    participant MyPy as MyPy Type Checker
    participant Code as opentelemetry.py
    participant OTEL as OpenTelemetry SDK
    
    Note over MyPy,Code: Before Fix (Multi-line import)
    MyPy->>Code: Check import on line 1007-1009
    Code->>OTEL: Try: from opentelemetry.sdk._logs<br/>import LogRecord as SdkLogRecord
    Note over MyPy: type: ignore on wrong line (1008)<br/>Reports attr-defined error on line 1013
    
    Note over MyPy,Code: After Fix (Single-line import)
    MyPy->>Code: Check import on line 1007
    Code->>OTEL: Try: from opentelemetry.sdk._logs<br/>import LogRecord as SdkLogRecord
    Note over Code: type: ignore[attr-defined] on same line (1007)
    MyPy->>Code: Suppresses attr-defined error
    
    alt Import Fails (OTEL >= 1.39.0)
        Code->>OTEL: Except: from opentelemetry.sdk._logs._internal<br/>import LogRecord as SdkLogRecord
        Note over Code: type: ignore[attr-defined, no-redef] on line 1009
        MyPy->>Code: Suppresses attr-defined and no-redef errors
    end
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@krrishdholakia krrishdholakia changed the base branch from main to litellm_oss_staging_01_24_2026 February 5, 2026 07:03
@krrishdholakia krrishdholakia merged commit 424e1bb into BerriAI:litellm_oss_staging_01_24_2026 Feb 5, 2026
5 of 8 checks passed
krrishdholakia added a commit that referenced this pull request Feb 5, 2026
krrishdholakia added a commit that referenced this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.