Skip to content

Unfinished Variable::Quantified: T in factory-boy's LazyAttribute #4547

Closed

Description

@mikicz

Describe the Bug

I have code like this, using django and factory-boy. The specific django model has two FKs, which both have the identical attr. In the example below that obviously complains about SomeModel not existing as well, but in my real world case those imports are fine.

import factory.django

class SomeFactory(factory.django.DjangoModelFactory[SomeModel]):
    attr_match = factory.LazyAttribute(
        lambda obj: (
            obj.fk_1.attr == obj.fk_2.attr
            if obj.fk_1 is not None and obj.fk_2 is not None
            else False
        )
    )

    class Meta:
        model = SomeModel

When I run pyrefly check on 1.2.0, I get the following error:

ERROR Unfinished Variable::Quantified: T [internal-error]
 --> src/min_rep.py:7:32
  |
7 |             if obj.fk_1 is not None and obj.fk_2 is not None
  |                                ^^^^
  |
  Sorry, Pyrefly encountered an internal error, this is always a bug in Pyrefly itself
  Please report the bug at https://github.com/facebook/pyrefly/issues/new

Sandbox Link

Sandbox doesn't have factory-boy installed

(Only applicable for extension issues) IDE Information

No response

Activity

  1. self-assigned this
    on Aug 15, 2026
  2. added theissue type on Aug 15, 2026
  3. github-actions commented on Aug 29, 2026

    @github-actions

    This issue has someone assigned, but has not had recent activity for more than 2 weeks.

    If you are still working on this issue, please add a comment so everyone knows. Otherwise, please unassign yourself and allow someone else to take over.

    Thank you for your contributions!

  4. rchen152 commented on Nov 6, 2026

    @rchen152
    Contributor

    This is fixed. Here's a self-contained repro that errors at pyrefly 1.4.1 and not in the sandbox:

    from typing import Any, Callable, Generic, TypeVar
    
    T = TypeVar("T")
    V = TypeVar("V")
    
    class Resolver(Generic[T]):
        def __getattr__(self, name: str) -> Any: ...
    
    class LazyAttribute(Generic[T, V]):
        def __init__(self, function: Callable[[Resolver[T]], V]) -> None: ...
    
    x = LazyAttribute(
        lambda obj: (
            obj.fk_1.attr == obj.fk_2.attr
            if obj.fk_1 is not None and obj.fk_2 is not None
            else False
        )
    )
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions