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

Add deprecated-attribute message #8855

Closed
jacobtylerwalls opened this issue Jul 15, 2023 · 20 comments · Fixed by #8857 or #9461
Closed

Add deprecated-attribute message #8855

jacobtylerwalls opened this issue Jul 15, 2023 · 20 comments · Fixed by #8857 or #9461
Assignees
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@jacobtylerwalls
Copy link
Member

Current problem

Similar to deprecated-method, we could have deprecated-attribute to warn for uses like this:

>>> sqlite3.version_info
<stdin>:1: DeprecationWarning: version_info is deprecated and will be removed in Python 3.14

Desired solution

deprecated-attribute message and then add attributes that were missed from python what's new documents, such as in 3.12:

  • sqlite3.version
  • sqlite3.version_info
  • generator.throw
  • agen.throw
  • sys.last_type
  • sys.last_value
  • sys.last_traceback
  • calendar.January
  • calendar.February

Additional context

The generator changes might be difficult to make, but the sys ones would be easy and high value because they were deprecated only in docs, not with code warnings.

@jacobtylerwalls jacobtylerwalls added Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 15, 2023
@AmanSal1
Copy link
Contributor

@jacobtylerwalls Can I work on this ?

@jacobtylerwalls
Copy link
Member Author

Sure thing! Feel free to open a draft PR if you have questions about something along the way.

@jacobtylerwalls jacobtylerwalls added Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Jul 15, 2023
@AmanSal1
Copy link
Contributor

@jacobtylerwalls Can you just sum up what all has to be done ?

@jacobtylerwalls
Copy link
Member Author

Sure, you should take a look at the implementation of the other deprecated-* messages such as deprecated-method, look at how they are triggered, and figure out how to trigger a new similar message for attributes. You can then adapt the functional tests for deprecated-method in a very similar way. Basically, use your IDE to search for deprecated-method and just look at everything you find.

You'll probably need to trigger your check from visit_attribute() instead of visit_call.

@AmanSal1
Copy link
Contributor

@jacobtylerwalls So till now what I have figured out is that:

1.DEPRECATED_ATTRIBUTE_MESSAGE = {
"W4906": (
"Using deprecated attribute %r",
"deprecated-attribute",
"The attribute is marked as deprecated and will be removed in the future.",
{"old_names": [("WXXXX", "old-deprecated-attribute")], "shared": True},
),
}
Add this message in the DeprecatedMixin class and then make change the add a function called as deprecated_attributes () in it .

Can you tell is right ?

@jacobtylerwalls
Copy link
Member Author

Yep sounds right!

@AmanSal1
Copy link
Contributor

@jacobtylerwalls In the file "typecheck.py," the function "visit_attributes()" will also be modified because there are multiple functions with the same name in different files. I wanted to confirm with you if this understanding is correct.

@jacobtylerwalls
Copy link
Member Author

That doesn't sound quite right, I think only the visit_attribute() method needs changing in the file with the deprecation checker. If it doesn't exist you'll need to create it (it's an override).

@AmanSal1
Copy link
Contributor

AmanSal1 commented Jul 15, 2023

@jacobtylerwalls "deprecated.py" In this file, there is no definition of 'visit_attributes()' method. I suppose I have to create it then?

@AmanSal1
Copy link
Contributor

Or are you talking about the visit_attributes() method in the "class_checker.py" file ?

@jacobtylerwalls
Copy link
Member Author

@jacobtylerwalls "deprecated.py" In this file, there is no definition of 'visit_attributes()' method. I suppose I have to create it then?

Yes, this is needed. No "s" at the end of attribute. If you check the parent classes you'll see it's an override.

@AmanSal1
Copy link
Contributor

Wrote it by mistake . So I have to create a method with this name in deprecated.py as it is not there ?

@jacobtylerwalls
Copy link
Member Author

Right, it will have the same signature as in the parent class.

@AmanSal1
Copy link
Contributor

Okay got it !!

@AmanSal1
Copy link
Contributor

@jacobtylerwalls Like I have made changes in the deprected.py I want to test them how can I test them and know if the changes are right or not. Like do I have to create a python file and then give to pylint something like that ?

@jacobtylerwalls
Copy link
Member Author

You can take a look at https://pylint.readthedocs.io/en/stable/development_guide/contributor_guide/tests/index.html for those topics.

@AmanSal1
Copy link
Contributor

@jacobtylerwalls For adding the test for the "attrribute" do we also need to update the "check_deprecate_method" or the other related methods because I am running a command "python -m pytest unittest_deprecated.py" and my 4 test are failing .Can you guide me little bit?

1

@jacobtylerwalls
Copy link
Member Author

At this point a draft PR would be easier to talk over, provides more info than a screen shot 👍

@AmanSal1
Copy link
Contributor

Ok will draft soon

@AmanSal1
Copy link
Contributor

Can you review it I accidently got some whitespace and all but can you review the logic ?

@jacobtylerwalls jacobtylerwalls added this to the 3.0.0a7 milestone Jul 21, 2023
@jacobtylerwalls jacobtylerwalls removed this from the 3.0.0a7 milestone Aug 6, 2023
@jacobtylerwalls jacobtylerwalls added this to the 3.0.0b1 milestone Aug 6, 2023
@jacobtylerwalls jacobtylerwalls removed this from the 3.0.0b1 milestone Sep 7, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.1.0 milestone Oct 28, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Mar 3, 2024
New Features
------------

- Skip ``consider-using-join`` check for non-empty separators if an ``suggest-join-with-non-empty-separator`` option is set to ``no``.

  Closes #8701 (`#8701 <https://github.com/pylint-dev/pylint/issues/8701>`_)

- Discover ``.pyi`` files when linting.

  These can be ignored with the ``ignore-patterns`` setting.

  Closes #9097 (`#9097 <https://github.com/pylint-dev/pylint/issues/9097>`_)

- Check ``TypeAlias`` and ``TypeVar`` (PEP 695) nodes for ``invalid-name``.

  Refs #9196 (`#9196 <https://github.com/pylint-dev/pylint/issues/9196>`_)

- Support for resolving external toml files named pylintrc.toml and .pylintrc.toml.

  Closes #9228 (`#9228 <https://github.com/pylint-dev/pylint/issues/9228>`_)

- Check for `.clear`, `.discard`, `.pop` and `remove` methods being called on a set while it is being iterated over.

  Closes #9334 (`#9334 <https://github.com/pylint-dev/pylint/issues/9334>`_)



New Checks
----------

- New message `use-yield-from` added to the refactoring checker. This message is emitted when yielding from a loop can be replaced by `yield from`.

  Closes #9229. (`#9229 <https://github.com/pylint-dev/pylint/issues/9229>`_)

- Added a ``deprecated-attribute`` message to check deprecated attributes in the stdlib.

  Closes #8855 (`#8855 <https://github.com/pylint-dev/pylint/issues/8855>`_)


False Positives Fixed
---------------------

- Fixed false positive for ``inherit-non-class`` for generic Protocols.

  Closes #9106 (`#9106 <https://github.com/pylint-dev/pylint/issues/9106>`_)

- Exempt ``TypedDict`` from ``typing_extensions`` from ``too-many-ancestor`` checks.

  Refs #9167 (`#9167 <https://github.com/pylint-dev/pylint/issues/9167>`_)



False Negatives Fixed
---------------------

- Extend broad-exception-raised and broad-exception-caught to except*.

  Closes #8827 (`#8827 <https://github.com/pylint-dev/pylint/issues/8827>`_)

- Fix a false-negative for unnecessary if blocks using a different than expected ordering of arguments.

  Closes #8947. (`#8947 <https://github.com/pylint-dev/pylint/issues/8947>`_)



Other Bug Fixes
---------------

- Improve the message provided for wrong-import-order check.  Instead of the import statement ("import x"), the message now specifies the import that is out of order and which imports should come after it.  As reported in the issue, this is particularly helpful if there are multiple imports on a single line that do not follow the PEP8 convention.

  The message will report imports as follows:
  For "import X", it will report "(standard/third party/first party/local) import X"
  For "import X.Y" and "from X import Y", it will report "(standard/third party/first party/local) import X.Y"
  The import category is specified to provide explanation as to why pylint has issued the message and guidence to the developer on how to fix the problem.

  Closes #8808 (`#8808 <https://github.com/pylint-dev/pylint/issues/8808>`_)



Other Changes
-------------

- Print how many files were checked in verbose mode.

  Closes #8935 (`#8935 <https://github.com/pylint-dev/pylint/issues/8935>`_)

- Fix a crash when an enum class which is also decorated with a ``dataclasses.dataclass`` decorator is defined.

  Closes #9100 (`#9100 <https://github.com/pylint-dev/pylint/issues/9100>`_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants