Skip to content

Improve fields annotations #10

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

Closed
K0Te opened this issue Jan 26, 2019 · 2 comments
Closed

Improve fields annotations #10

K0Te opened this issue Jan 26, 2019 · 2 comments

Comments

@K0Te
Copy link
Contributor

K0Te commented Jan 26, 2019

Hi,

I've tried checking my project and got lots of field-related warnings, most about extra parameters, duplicate parameters, etc.
I've narrowed issue down to Field signature and it's inherited classes.
Current signature is:
def __init__(self, **kwargs: Any): ...
And as example CharField:
def __init__(self, max_length: int = ..., **kwargs: Any): ...

Real Field signature has to accept all arguments as positional, and to do it's inherited classes. It might be not practical to supply more than 1-2 arguments as positional, but it's possible:

def __init__(
    self,
    verbose_name: str = ...,
    name: str = ...,
    primary_key: bool = ...,
    max_length: int = ...,
    unique: bool = ...,
    blank: bool = ...,
    null: bool = ...,
    db_index: bool = ...,
    rel: Any = ..., ## ???
    default: Any = ..., ## ???
    editable: bool = ...,
    serialize: bool = ...,
    unique_for_date: bool = ...,
    unique_for_month: bool = ...,
    unique_for_year: bool = ...,
    choices: Any = ..., # ???
    help_text: str = ...,
    db_column: Any = ..., # ???
    db_tablespace: Any = ..., # ???
    auto_created: bool = ...,
    validators: Any = ..., #???
) -> None: ...

So CharField's max_length is just one of Field parameters.

Please advise - should it be fixed directly, or is it an issue in automated code annotator ?
If it should be fixed manually - should all inherited fields duplicate Field signature and add new params, or will (new_param: Type, **kwargs) work fine ? I'm not sure if mypy will check Field signature in this case.

@mkurnikov
Copy link
Member

Try with latest master, I've just pushed some related changes.

@K0Te
Copy link
Contributor Author

K0Te commented Jan 28, 2019

It works fine now, thanks !
However, #6 #7 and #9 are still actual.

@K0Te K0Te closed this as completed Jan 28, 2019
@TonyRippy TonyRippy mentioned this issue Dec 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants