GithubHelp home page GithubHelp logo

Comments (3)

treykeown avatar treykeown commented on May 24, 2024
import msgspec
from typing import Generic, TypeVar

T = TypeVar('T')
T_int = TypeVar('T_int', bound=int)

class Base(msgspec.Struct, Generic[T], tag=True):
    """..."""


class Subclass(Base[int]):
    """..."""


class Bug(Subclass, Base[T_int], Generic[T_int]):
    """..."""


if __name__ == "__main__":
    enc = msgspec.msgpack.encode(Bug())
    dec = msgspec.msgpack.decode(enc, type=list[Bug])
    print(dec)
Traceback (most recent call last):
  File "/Users/.../scratch.py", line 21, in <module>
    dec = msgspec.msgpack.decode(enc, type=list[Bug])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.venv/lib/python3.12/site-packages/msgspec/_utils.py", line 113, in get_class_annotations
    mro, typevar_mappings = _get_class_mro_and_typevar_mappings(obj)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../.venv/lib/python3.12/site-packages/msgspec/_utils.py", line 90, in _get_class_mro_and_typevar_mappings
    inner(obj, {})
  File "/Users/.../.venv/lib/python3.12/site-packages/msgspec/_utils.py", line 88, in inner
    inner(b, new_scope)
  File "/Users/.../.venv/lib/python3.12/site-packages/msgspec/_utils.py", line 88, in inner
    inner(b, new_scope)
             ^^^^^^^^^
UnboundLocalError: cannot access local variable 'new_scope' where it is not associated with a value

from msgspec.

treykeown avatar treykeown commented on May 24, 2024

I've since fixed how my classes are structured, but this is still an issue any time a generic class appears both in a parent class and in a child class.

from msgspec.

jcrist avatar jcrist commented on May 24, 2024

Thanks for the excellent reproducible issue, this should be fixed by #626.

from msgspec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.