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

Runtime changes for typeshed parameter annotations merge #4505

Merged
merged 2 commits into from
Aug 8, 2024

Conversation

Avasam
Copy link
Contributor

@Avasam Avasam commented Jul 22, 2024

Summary of changes

Extracted from #4504
These are the runtime changes that should be reviewed more carefully.

Works towards #2345

Pull Request Checklist

@Avasam Avasam force-pushed the runtime-changes-for-typeshed-merge branch from dd3af1c to f7b0e67 Compare July 22, 2024 06:38
@Avasam Avasam changed the title runtime changes for typeshed merge Runtime changes for typeshed parameter annotations merge Jul 22, 2024
return cls.from_environment()
# otherwise, assume it's a string.
return cls.from_string(param)
return cls.from_environment()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this gracious fallback is undesired, I can explicitly raise instead.

Copy link
Contributor

@abravalheri abravalheri Aug 8, 2024

Choose a reason for hiding this comment

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

Let's raise it explicitly because before cls.from_environment() was only used in the case of None. I suspect that the previous fallback to cls.from_string would cause a TypeError if the user passed non-sensical args.

We propbably don't want to change that behaviour

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Raising an error instead of a fallback makes sense since the param unexpectedly goes unused.

It was an AttributeError because non-string first argument to shlex is assumed to be a stream.

  File "C:\Program Files\Python39\lib\shlex.py", line 140, in read_token
    nextchar = self.instream.read(1)
AttributeError: 'int' object has no attribute 'read'

At the from_param level it should really be a TypeError, but that's technically a non-backwards compatible change.

I raise an AttributeError, maybe can be changed for a TypeError next major version (or now if you don't mind the error type change)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @Avasam, I am happy with either.

I don't think that changing to TypeError should be a big impact because it looks like a very edge-y case.
Probably the important part is to raise the exception, not the exact exception class. So I am OK with risking it.

But equally happy to take the conservative approach, given how susceptible setuptools is to Hyrum's Law...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about this: Keep it to AttributeError for this PR, I'll open a follow-up that changes to TypeError that you can merge before the next major update. That should cover our bases and improve the communicated error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @Avasam.

return cls.from_environment()
# otherwise, assume it's a string.
return cls.from_string(param)
return cls.from_environment()
Copy link
Contributor

@abravalheri abravalheri Aug 8, 2024

Choose a reason for hiding this comment

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

Let's raise it explicitly because before cls.from_environment() was only used in the case of None. I suspect that the previous fallback to cls.from_string would cause a TypeError if the user passed non-sensical args.

We propbably don't want to change that behaviour

setuptools/command/editable_wheel.py Outdated Show resolved Hide resolved
@@ -126,10 +127,12 @@ class Extension(_Extension):
specified on Windows. (since v63)
"""

def __init__(self, name, sources, *args, **kw):
def __init__(
self, name: str, sources: list[str], *args, py_limited_api: bool = False, **kw
Copy link
Contributor

Choose a reason for hiding this comment

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

Jason might have added support for PathLikesources recently in pypa/distutils#237 (https://github.com/pypa/setuptools/blob/v72.2.0/setuptools/_distutils/extension.py#L29).

(PS.: granted they are incompatible with SETUPTOOLS_USE_DISTUTILS=stdlib but that is a deprecated code path).

Copy link
Contributor Author

@Avasam Avasam Aug 8, 2024

Choose a reason for hiding this comment

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

Thanks for the heads up. That added annotation isn't necessary for this PR. I'd rather avoid possible type conflicts with sdtlib distutils for now so I'll just remove the annotation to sources. I'll tackle that later, and happily bring in StrPath/PathLike updates from _distutils.

@Avasam Avasam force-pushed the runtime-changes-for-typeshed-merge branch from 4a161cd to 9c71fd8 Compare August 8, 2024 16:03
Co-authored-by: Anderson Bravalheri <andersonbravalheri@gmail.com>
@abravalheri abravalheri merged commit 7923172 into pypa:main Aug 8, 2024
19 of 21 checks passed
@abravalheri
Copy link
Contributor

Thank you!

@Avasam Avasam deleted the runtime-changes-for-typeshed-merge branch August 8, 2024 17:51
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.

2 participants