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

Call expression not allowed in type expression #4

Open
siwoo-destim opened this issue Oct 22, 2024 · 1 comment
Open

Call expression not allowed in type expression #4

siwoo-destim opened this issue Oct 22, 2024 · 1 comment
Labels
typing Issues with type checkers

Comments

@siwoo-destim
Copy link

siwoo-destim commented Oct 22, 2024

Call expression not allowed in type expression

I really like this library due to its Pydantic-friendly features. I hope more people get to use this repository.

However, when I use "WithOptions" while defining a model, I encounter some issues:

def test():
    return "test"

class User(NodeModel):
    profile_image: str
    bio: str
    display_name: str
    
    username: WithOptions(str, unique=True) = Field(default_factory=test)

image

The type checker gives me a warning, and it's not ideal to see that. After some searching, I found a related issue on this page:

microsoft/pylance-release#5457
(According to above issues post, it seems to be caused by Pylance update)
So, I tried the following code:

def test():
    return "test"

class User(NodeModel):
    profile_image: str
    bio: str
    display_name: str
    username: Annotated[str, WithOptions(str, unique=True)] = Field(default_factory=test)

While warning has disappeared, "WithOptions" doesn't guarantee uniqueness.

Your environment

  • Version of pyneo4j-ogm: pyneo4j-ogm 0.6.0
  • Version of pydantic: v2
  • Version of python: Python 3.11.0

Steps to reproduce

def test():
    return "test"

class User(NodeModel):
    profile_image: str
    bio: str
    display_name: str
    
    username: WithOptions(str, unique=True) = Field(default_factory=test)

Call expression not allowed in type expression

Expected Behavior

No error

Actual Behavior

Call expression not allowed in type expression

@groc-prog
Copy link
Owner

Hey, I'm happy you like the library so far! I did not have any time to work on anything lately due to personal reasons, but I am planning to get started again some time soon (fingers crossed).

Regarding your issue, it's something we used to just supress as mentioned in here in our production codebases. I currently don't know of any possible workaround, as I think we would need to implement it some other way for type checkers to not complain.

If you have any suggestions for another implementation, feel free to share your thoughts. Breaking changes wouldn't be a problem, since I plan on reworking some core mechanics for the next release anyways, once i find the time for it.

@groc-prog groc-prog added the typing Issues with type checkers label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typing Issues with type checkers
Projects
None yet
Development

No branches or pull requests

2 participants