FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix pos-only params in `os` module by sobolevn · Pull Request #11505 · python/typeshed · GitHub

Repository navigation

Fix pos-only params in os module - #11505

Merged
AlexWaygood merged 3 commits into
mainfrom
pos-only-os
Feb 29, 2024
Merged

AlexWaygood merged 3 commits into
mainfrom
pos-only-os

Conversation

sobolevn commented Feb 29, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

Problem:

/home/runner/work/typeshed/typeshed/stdlib/os/__init__.pyi
  /home/runner/work/typeshed/typeshed/stdlib/os/__init__.pyi:872:33 - error: Position-only parameter not allowed after parameter that is not position-only (reportGeneralTypeIssues)
  /home/runner/work/typeshed/typeshed/stdlib/os/__init__.pyi:873:34 - error: Position-only parameter not allowed after parameter that is not position-only (reportGeneralTypeIssues)

It is the same notation for __arg1: X, *args: X
Link: https://mypy-play.net/?mypy=latest&python=3.12&gist=b35729b668bf88a0d98a78a8d37c5be1

This comment has been minimized.

Comment thread stdlib/os/__init__.pyi
Comment on lines +872 to +873
def execl(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ...
def execlp(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Using PEP646 feels unnecessarily complicated here (and e.g. pytype still doesn't support PEP646 -- it just falls back to Any when it sees Unpack, I believe). Can't we just do this?

Suggested change
def execl(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ...
def execlp(file: StrOrBytesPath, *args: Unpack[tuple[StrOrBytesPath, Unpack[tuple[StrOrBytesPath, ...]]]]) -> NoReturn: ...
def execl(file: StrOrBytesPath, arg0: StrOrBytesPath, /, *args: StrOrBytesPath) -> NoReturn: ...
def execlp(file: StrOrBytesPath, arg0: StrOrBytesPath, /, *args: StrOrBytesPath) -> NoReturn: ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, looks easier!

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>

Copy link
Copy Markdown
Member

Oh interesting. Stubtest is correct; you really can pass file as a keyword argument:

>>> import os
>>> os.execl(file='foo')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen os>", line 548, in execl
ValueError: execv() arg 2 must not be empty

Copy link
Copy Markdown
Member Author

Hm, this way we have a stubtest problem:

error: os.execl is inconsistent, stub argument "file" should be positional or keyword (remove leading double underscore)
Stub: in file stdlib/os/__init__.pyi:872
def (Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]], Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]], *args: Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]]) -> Never
Runtime: in file /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/os.py:538
def (file, *args)

error: os.execlp is inconsistent, stub argument "file" should be positional or keyword (remove leading double underscore)
Stub: in file stdlib/os/__init__.pyi:873
def (Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]], Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]], *args: Union[builtins.str, builtins.bytes, os.PathLike[builtins.str], os.PathLike[builtins.bytes]]) -> Never
Runtime: in file /opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/os.py:553
def (file, *args)

This comment has been minimized.

Copy link
Copy Markdown
Member

I guess your PEP646 way is the best way, in that case :)

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

AlexWaygood merged commit 217166b into main Feb 29, 2024
AlexWaygood deleted the pos-only-os branch February 29, 2024 09:01
danieleades pushed a commit to danieleades/typeshed that referenced this pull request Mar 1, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL