Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pylint raises error saying "default" isn't valid for TypeVar #9672

Closed
nfelt14 opened this issue May 24, 2024 · 4 comments · Fixed by #9785
Closed

Pylint raises error saying "default" isn't valid for TypeVar #9672

nfelt14 opened this issue May 24, 2024 · 4 comments · Fixed by #9785
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@nfelt14
Copy link

nfelt14 commented May 24, 2024

Bug description

After upgrading to typing_extensions==4.12.0, pylint is raising the following error for TypeVars that have default values:

E1123: Unexpected keyword argument 'default' in constructor call (unexpected-keyword-arg)

The same code does not raise an error when using typing_extensions==4.11.0.

I believe that it is following the import to the typing_extensions module but it is not respecting the if statement that blocks the import of the TypeVar class from the typing module if PEP-696 isn't implemented.

from typing_extensions.py:

if _PEP_696_IMPLEMENTED:
    from typing import TypeVar
else:
    # Add default and infer_variance parameters from PEP 696 and 695
    class TypeVar(metaclass=_TypeVarLikeMeta):
        """Type variable."""

Originally filed python/typing_extensions#411

Configuration

No response

Command used

`pylint .`

Pylint output

`E1123: Unexpected keyword argument 'default' in constructor call (unexpected-keyword-arg)`

Expected behavior

No error should be raised.

Pylint version

pylint 3.2.1
astroid 3.2.2
Python 3.11.9 (tags/v3.11.9:de54cf5, Apr  2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]

OS / Environment

No response

Additional dependencies

typing_extensions==4.12.0
@nfelt14 nfelt14 added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label May 24, 2024
@jacobtylerwalls
Copy link
Member

Thanks for the report. Can you include a sample usage that raises the lint error?

@nfelt14
Copy link
Author

nfelt14 commented Jul 9, 2024

from typing_extensions import TypeVar

StringAlias = TypeVar("StringAlias", bound=str, default=str)

@DanielNoord
Copy link
Collaborator

pylint won't understand _PEP_696_IMPLEMENTED as we don't have support for such control flow analysis using non-stdlib symbols.

@jacobtylerwalls
Copy link
Member

I don't think that's the issue. I think we need to adjust safe_infer()'s "function ambiguity" special handling to catch the difference between the two functions.

We probably should audit everything for whether it should use infer_all, but we have this special handling in safe_infer in the meantime. I'll take a look.

@jacobtylerwalls jacobtylerwalls self-assigned this Jul 9, 2024
@jacobtylerwalls jacobtylerwalls added False Positive 🦟 A message is emitted but nothing is wrong with the code 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 9, 2024
@jacobtylerwalls jacobtylerwalls added this to the 3.2.6 milestone Jul 10, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code 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