Skip to content

Conversation

@Jdwashin9
Copy link

@Jdwashin9 Jdwashin9 commented Apr 18, 2025

Fixes #18940 (hopefully; I wrote a test, but I'm having trouble running it)

How this PR changes mypy:

Deleted the line mentioned in the original issue, added an import called "types", and made a few other small changes.

I think there's a problem with the test I wrote. For some reason, when I type dmypy check ., it says Daemon has died. For the sake of my team's academic assignment, I'd like to label this as a work in progress tentatively, then return to it later because I can't let anyone else claim it for now.

@github-actions

This comment has been minimized.

Copy link
Collaborator

@A5rocks A5rocks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you accidentally committed a bunch of files? The lxml changes and the std_types changes are not necessary and shouldn't be in this PR. (and changing our vendored typeshed is a very bad idea)

I also would prefer another implementation.

.. note::

When adding types, the convention is to import types
When adding types, the convention is to import types as std_types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is talking about importing typing and this isn't the convention.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the convention is "never alias-import stdlib modules unless strictly necessary". Please revert this doc change along with all imports garbled in other files.

# and isinstance(ct.arg_types[0], TypeVarType)
and ct.arg_types[0] == ct.ret_type
):
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looks like a special case for this decorator:

def f(x: T) -> T:
  return x

you should add a special case in addition to this.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, technically this line is limiting to that special case. And this will even fix the linked issue, two callables of that shape will compare equal AFAIC.

But this also makes the following (completely wrong) deco generate a signature:

def deco(fn: str) -> str: ...

@deco
def foo():
    print()

So I agree there should be one more special case, not just blanket "one-arg function returning its arg unchanged".

Copy link

@asottile-sentry asottile-sentry Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that any identity function should be fine here -- if that decorator happens to have the wrong types that's not really this code's problem (it's just trying to unwrap the underlying callable) and I suspect there's many many ways to type an identity function with varying specificity making this particular condition difficult-to-impossible to write correctly exhaustively

# and isinstance(ct.arg_types[0], TypeVarType)
and ct.arg_types[0] == ct.ret_type
):
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, technically this line is limiting to that special case. And this will even fix the linked issue, two callables of that shape will compare equal AFAIC.

But this also makes the following (completely wrong) deco generate a signature:

def deco(fn: str) -> str: ...

@deco
def foo():
    print()

So I agree there should be one more special case, not just blanket "one-arg function returning its arg unchanged".

.. note::

When adding types, the convention is to import types
When adding types, the convention is to import types as std_types
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the convention is "never alias-import stdlib modules unless strictly necessary". Please revert this doc change along with all imports garbled in other files.


[case testCoroutineImportTypesAsT]
import types as t
import types as std_types as t
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed is great, but this isn't even valid python.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@Jdwashin9
Copy link
Author

Ok, I reverted the std_types changes, but I am still having trouble getting my Daemon to run. After talking to my instructor, I have decided I will no longer work on this issue, as it will not meet the requirements for my classwork assignment.

@Jdwashin9 Jdwashin9 closed this Apr 25, 2025
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

Successfully merging this pull request may close these issues.

dmypy gives up on trivial decorator

4 participants