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

PyCharm IDE warnings #2932

Closed
mark99i opened this issue Sep 21, 2024 · 6 comments
Closed

PyCharm IDE warnings #2932

mark99i opened this issue Sep 21, 2024 · 6 comments

Comments

@mark99i
Copy link

mark99i commented Sep 21, 2024

Hello, im using Pycharm with latest peewee 3.17.6

PyCharm 2024.2.2 (Professional Edition)
Build #PY-242.22855.92, built on September 19, 2024

I trying using playhouse and IDE throws error

from playhouse.migrate import *
               ~~~~~~~

# Cannot find reference 'migrate' in '__init__.pyi' 

Also I trying using this code IDE throws warning

class TestModel(BaseModel):
    mystring: str | CharField = CharField()
    myint: int | IntegerField = IntegerField(null=True)

TestModel.select().where(
    TestModel.mystring.in_(['one', 'two', 'three'])
)

# 'three'])
#        ~~
# Parameter(s) unfilled Possible callees: (...: CharField, ...) 

TestModel.select().where(
    (TestModel.mystring == 'one') &
    (TestModel.mystring == 'two') &
    (TestModel.myint.is_null(False))
)

# (TestModel.myint.is_null(False))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unexpected type(s): (Expression) Possible type(s): (bool) (int) 

Since this code is quite working (playhouse too), I think these are errors on the part of the IDE, but is it possible to fix them on your part?

@coleifer
Copy link
Owner

The code is fine, the IDE is not. Python is a very dynamic language and we use that to our purpose in peewee.

@mark99i
Copy link
Author

mark99i commented Sep 25, 2024

The code is fine, the IDE is not. Python is a very dynamic language and we use that to our purpose in peewee.

I have previously seen your posts saying that you are against type hinting in python
I like python myself because of its dynamism, but when a project grows into several dozen files and dozens of structures, it becomes very difficult to maintain and develop new functionality without typing

in recent versions, there are big improvements in terms of type hinting (for example, Self), is there a chance of an implementation of type hinting in peewee?
or maybe you have your own action plan on how to support large projects without typing?

at the moment, I have found a workaround in the form of overriding the get* methods in my BaseModel, something like here:

class BaseModel(Model):
    @classmethod
    def get_or_none(cls, *args, **kwargs) -> Self | None:
        return super().get_or_none(*args, **kwargs)

    @classmethod
    def get_by_id(cls, pk: int) -> Self:
        return super().get_by_id(pk)

    @classmethod
    def get(cls, *query, **filters) -> Self:
        return super().get(*query, **filters)

    @classmethod
    def get_or_create(cls, **kwargs) -> tuple[Self, bool]:
        return super().get_or_create(**kwargs)

class User(BaseModel):
    ...

user = User.get_by_id(1)
# user type is User

the methods select() and where() and many others seem to return the type None, although you probably would like to return ModelSelect or similar

what is your current opinion on typing? perhaps this is planned in peewee 4.x?

@Seluj78
Copy link

Seluj78 commented Sep 25, 2024

The problem of playhouse imports not being found on PyCharm is also something I am encountering, but I think it's more of a Jetbrains issue and needs to be reported on their end, since the code works but it's just their linter that is broken

@coleifer
Copy link
Owner

When I want types I reach for a statically-typed language.

@mark99i
Copy link
Author

mark99i commented Sep 25, 2024

The problem of playhouse imports not being found on PyCharm is also something I am encountering, but I think it's more of a Jetbrains issue and needs to be reported on their end, since the code works but it's just their linter that is broken

Hmm I just checked one of the previous ones, and everything seems to be working fine there. Apparently it was broken in the last one

PyCharm 2023.2 (Community Edition)
Build #PC-232.8660.197, built on July 26, 2023

When I want types I reach for a statically-typed language.

Have you ever wanted to take advantage of both types of languages?
Why do you think TypeScript is so popular now?

I'm interested in your opinion as a professional, I understand that adding type hinting to peewee is a huge job, and maybe you're saying that because you don't want to or you don't have time do it.

Suppose you had recently started doing a similar project in Python, would you use type hints?

@coleifer
Copy link
Owner

Popularity, however you quantify it, isn't a meaningful metric for me. Programming goes through fads. Type hinting, for me, is bad for a couple reasons -- 1) it's not enforced, 2) I find it noisy and distracting, 3) well-formatted docstrings can accomplish the same thing and were the de-facto way to indicate types along w/other useful information and are compatibe with all versions of Python. I have a strong distaste for this kind of code.

If I want typing I use go or c.

would you use type hints

Never.

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

No branches or pull requests

3 participants