Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Types are being enforced on non-cdef classes #4196

Closed
da-woods opened this issue May 27, 2021 · 1 comment
Closed

[BUG] Types are being enforced on non-cdef classes #4196

da-woods opened this issue May 27, 2021 · 1 comment

Comments

@da-woods
Copy link
Contributor

Describe the bug +To Reproduce

From the users mailing list (https://groups.google.com/g/cython-users/c/R4YQzdIOPSQ):

class BaseModel:
    pass

class Field:
    def __init__(self, *args, **kwds):
        pass

class ServiceRow(BaseModel):
    """An individual record."""

    service_id: int = Field(..., description="The ID for the service.", alias="id")
    name: str = Field(..., description="Displayable Name for the service.")

Fails at runtime with

name: str = Field(..., description="Displayable Name for the service.")
TypeError: Expected str, got Field

Generated C code includes

if (!(likely(PyString_CheckExact(__pyx_t_2))||((__pyx_t_2) == Py_None) || __Pyx_RaiseUnexpectedTypeError("str", __pyx_t_2))) __PYX_ERR(0, 12, __pyx_L1_error)

Expected behavior

It's just regular Python code - it shouldn't enforce the types

Environment (please complete the following information):

  • OS: Linux
  • Python version 3.8.9
  • Cython version: 3.0a7

Additional context

Bisect suggests b2b81c9 (slightly unsurprisingly).

@stevenj
Copy link

stevenj commented May 27, 2021

I can also add that

# cython: annotation_typing=False

added to the top of the file does not seem to work around the issue either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants