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

Issue with python 3.12 and date and datetime fields. #425

Closed
matejsp opened this issue Dec 31, 2023 · 3 comments · Fixed by #427
Closed

Issue with python 3.12 and date and datetime fields. #425

matejsp opened this issue Dec 31, 2023 · 3 comments · Fixed by #427
Milestone

Comments

@matejsp
Copy link
Contributor

matejsp commented Dec 31, 2023

When running pylint on 3.11 everthing works. However under python 3.12 for date and datetime fields we started to get pylint errors:

account/models/bank_transaction.py:42: [E1101(no-member), BankTransaction.to_dict] Instance of 'DateField' has no 'day' member
account/models/bank_transaction.py:42: [E1101(no-member), BankTransaction.to_dict] Instance of 'DateField' has no 'month' member
account/models/bank_transaction.py:42: [E1101(no-member), BankTransaction.to_dict] Instance of 'DateField' has no 'year' member
account/models/user_profile.py:240: [E1101(no-member), UserProfile.get_report] Instance of 'DateTimeField' has no 'month' member
account/models/user_profile.py:240: [E1101(no-member), UserProfile.get_report] Instance of 'DateTimeField' has no 'year' member
class BankTransaction(models.Model):
    book_date = models.DateField('Book date', db_index=True)
    val_date = models.DateField('Val date', db_index=True)

    def to_dict(self):
        return {
            'id': self.id,
            'bookDate': datetime.datetime(year=self.book_date.year, month=self.book_date.month, day=self.book_date.day),
            'valDate': datetime.datetime(year=self.val_date.year, month=self.val_date.month, day=self.val_date.day)
       }

class UserProfile(models.Model):
    user = models.OneToOneField(auth_models.User, on_delete=models.CASCADE)

    def get_volume_report(self) -> typing.List[typing.List]:
        current_month = datetime.datetime(self.user.date_joined.year, self.user.date_joined.month, 1)

We are using:
django==4.2.8
pylint==3.0.3
pylint-django==2.5.5
pylint-plugin-utils==0.8.2
pylint-protobuf==0.22.0

@matejsp
Copy link
Contributor Author

matejsp commented Dec 31, 2023

Reproducable test:

import datetime

from django.contrib.auth import models as auth_models
from django.db import models


class BankTransaction(models.Model):
    book_date = models.DateField('Book date', db_index=True)
    val_date = models.DateField('Val date', db_index=True)

    def to_dict(self):
        return {
            'id': self.id,
            'bookDate': datetime.datetime(year=self.book_date.year, month=self.book_date.month, day=self.book_date.day),
            'valDate': datetime.datetime(year=self.val_date.year, month=self.val_date.month, day=self.val_date.day)
        }


class UserProfile(models.Model):
    user = models.OneToOneField(auth_models.User, on_delete=models.CASCADE)

    def get_volume_report(self) -> datetime.datetime:
        return datetime.datetime(self.user.date_joined.year, self.user.date_joined.month, 1)
pylint --load_plugins pylint_django pylint_django_test.py
(venv-py3.12) ➜ pylint --load_plugins pylint_django pylint_django_test.py 
************* Module pylint_django_test
pylint_django_test.py:1:0: E5110: Django was not configured. For more information run pylint --load-plugins=pylint_django --help-msg=django-not-configured (django-not-configured)
pylint_django_test.py:14:47: E1101: Instance of 'DateField' has no 'year' member (no-member)
pylint_django_test.py:14:74: E1101: Instance of 'DateField' has no 'month' member (no-member)
pylint_django_test.py:14:100: E1101: Instance of 'DateField' has no 'day' member (no-member)
pylint_django_test.py:15:46: E1101: Instance of 'DateField' has no 'year' member (no-member)
pylint_django_test.py:15:72: E1101: Instance of 'DateField' has no 'month' member (no-member)
pylint_django_test.py:15:97: E1101: Instance of 'DateField' has no 'day' member (no-member)
pylint_django_test.py:23:33: E1101: Instance of 'DateTimeField' has no 'year' member (no-member)
pylint_django_test.py:23:61: E1101: Instance of 'DateTimeField' has no 'month' member (no-member)

@matejsp
Copy link
Contributor Author

matejsp commented Feb 11, 2024

Maybe something relevant to this (we should use _pydatetime.datetime):
https://github.com/pylint-dev/astroid/pull/2275/files#diff-36f231fac789e81cf43bea3b0e537bf1e9a922261fced3c055e015bdb9f5da7b

@matejsp
Copy link
Contributor Author

matejsp commented Feb 23, 2024

Any chance to get my PR reviewed and merged? It is really anoying bug stopping us from using pylint on python 3.12.

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

Successfully merging a pull request may close this issue.

2 participants