Skip to content

Commit

Permalink
Revert "Use parse_bool implementation from mypy" (#1792)
Browse files Browse the repository at this point in the history
* Revert "Use `parse_bool` implementation from mypy"

This reverts commit a6b3ba9

* Add comment
  • Loading branch information
intgr authored Oct 23, 2023
1 parent 0ce571e commit 6458248
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
11 changes: 10 additions & 1 deletion mypy_django_plugin/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
SemanticAnalyzerPluginInterface,
)
from mypy.semanal import SemanticAnalyzer
from mypy.semanal_shared import parse_bool
from mypy.types import AnyType, Instance, LiteralType, NoneTyp, TupleType, TypedDictType, TypeOfAny, UnionType
from mypy.types import Type as MypyType
from typing_extensions import TypedDict
Expand Down Expand Up @@ -176,6 +175,16 @@ def make_optional(typ: MypyType) -> MypyType:
return UnionType.make_union([typ, NoneTyp()])


# Duplicating mypy.semanal_shared.parse_bool because importing it directly caused ImportError (#1784)
def parse_bool(expr: Expression) -> Optional[bool]:
if isinstance(expr, NameExpr):
if expr.fullname == "builtins.True":
return True
if expr.fullname == "builtins.False":
return False
return None


def has_any_of_bases(info: TypeInfo, bases: Iterable[str]) -> bool:
for base_fullname in bases:
if info.has_base(base_fullname):
Expand Down
2 changes: 1 addition & 1 deletion mypy_django_plugin/transformers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from django.db.models.fields.reverse_related import ForeignObjectRel
from mypy.nodes import AssignmentStmt, NameExpr, TypeInfo
from mypy.plugin import FunctionContext
from mypy.semanal_shared import parse_bool
from mypy.types import AnyType, Instance, ProperType, TypeOfAny, UnionType
from mypy.types import Type as MypyType

from mypy_django_plugin.django.context import DjangoContext
from mypy_django_plugin.exceptions import UnregisteredModelError
from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.lib.helpers import parse_bool
from mypy_django_plugin.transformers import manytomany

if TYPE_CHECKING:
Expand Down
3 changes: 1 addition & 2 deletions mypy_django_plugin/transformers/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
from django.db.models.fields.reverse_related import ForeignObjectRel
from mypy.nodes import ARG_NAMED, ARG_NAMED_OPT, Expression
from mypy.plugin import FunctionContext, MethodContext
from mypy.semanal_shared import parse_bool
from mypy.types import AnyType, Instance, TupleType, TypedDictType, TypeOfAny, get_proper_type
from mypy.types import Type as MypyType

from mypy_django_plugin.django.context import DjangoContext, LookupsAreUnsupported
from mypy_django_plugin.lib import fullnames, helpers
from mypy_django_plugin.lib.fullnames import ANY_ATTR_ALLOWED_CLASS_FULLNAME
from mypy_django_plugin.lib.helpers import is_annotated_model_fullname
from mypy_django_plugin.lib.helpers import is_annotated_model_fullname, parse_bool
from mypy_django_plugin.transformers.models import get_or_create_annotated_type


Expand Down

0 comments on commit 6458248

Please sign in to comment.