[Python] pydantic v2.0.0 with pylint no-member warning

Discussão em 'Python' iniciado por Stack, Junho 7, 2025.

  1. Stack

    Stack Membro Participativo

    Questuion

    • in pydantic doc,pydantic ^2.0.0 not support like this a:Optional[str],but rather support a:Optional[str] = Field(default=None)
    • however,pylint check my code raise warning[E1101(no-member), get] Instance of 'FieldInfo' has no 'split' member

    from pydantic import BaseModel, Field
    from typing import Optional


    class A(BaseModel):
    a: Optional[str] = Field(default=None)


    def get(**kwargs):
    return A(**kwargs).a.split(" ")

    Attempt

    • if i use a:Optional[str] = None can solve all the problems above,but my project some fileds use Field
    • Declare pylint disable check in pyfile: pylint: disable=no-member
    • Declare pylint disable check in .pylinrc

    How can I solve the above problem

    Continue reading...

Compartilhe esta Página