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

Signature.bind TypeErrors could be more helpful #83901

Closed
RazerM mannequin opened this issue Feb 21, 2020 · 1 comment
Closed

Signature.bind TypeErrors could be more helpful #83901

RazerM mannequin opened this issue Feb 21, 2020 · 1 comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@RazerM
Copy link
Mannequin

RazerM mannequin commented Feb 21, 2020

BPO 39720
Nosy @RazerM

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2020-02-21.22:41:33.023>
labels = ['type-feature', 'library']
title = 'Signature.bind TypeErrors could be more helpful'
updated_at = <Date 2020-02-21.22:41:33.023>
user = 'https://github.com/RazerM'

bugs.python.org fields:

activity = <Date 2020-02-21.22:41:33.023>
actor = 'RazerM'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2020-02-21.22:41:33.023>
creator = 'RazerM'
dependencies = []
files = []
hgrepos = []
issue_num = 39720
keywords = []
message_count = 1.0
messages = ['362439']
nosy_count = 1.0
nosy_names = ['RazerM']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue39720'
versions = []

@RazerM
Copy link
Mannequin Author

RazerM mannequin commented Feb 21, 2020

Signature.bind does not tell you if a missing argument is keyword-only for example. I created the following snippet to examine the differences:

    import inspect
    
    def run(f):
        try:
            f()
        except TypeError as exc:
            print(exc.args[0])
        else:
            raise RuntimeError('Expected to raise!')
        sig = inspect.signature(f)
        try:
            sig.bind()
        except TypeError as exc:
            print(exc.args[0])
        else:
            raise RuntimeError('Expected to raise!')
        print()
    
    @run
    def f1(pos_only, /): ...
    
    @run
    def f2(pos_or_kw): ...
    
    @run
    def f3(*, kw_only): ...

Output on current 3.9 master:

f1() missing 1 required positional argument: 'pos_only'
missing a required argument: 'pos_only'

f2() missing 1 required positional argument: 'pos_or_kw'
missing a required argument: 'pos_or_kw'

f3() missing 1 required keyword-only argument: 'kw_only'
missing a required argument: 'kw_only'

I am willing to create a PR so that the TypeError for f3 says "missing a required keyword-only argument: 'kw_only'", if this would be accepted.

@RazerM RazerM mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 21, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
carljm added a commit to carljm/cpython that referenced this issue Oct 8, 2022
* main: (38 commits)
  pythongh-92886: make test_ast pass with -O (assertions off) (pythonGH-98058)
  pythongh-92886: make test_coroutines pass with -O (assertions off) (pythonGH-98060)
  pythongh-57179: Add note on symlinks for os.walk (python#94799)
  pythongh-94808: Fix regex on exotic platforms (python#98036)
  pythongh-90085: Remove vestigial -t and -c timeit options (python#94941)
  pythonGH-83901: Improve Signature.bind error message for missing keyword-only params (python#95347)
  pythongh-61105: Add default param, note on using cookiejar subclass (python#95427)
  pythongh-96288: Add a sentence to `os.mkdir`'s docstring. (python#96271)
  pythongh-96073: fix backticks in NEWS entry (pythonGH-98056)
  pythongh-92886: [clinic.py] raise exception on invalid input instead of assertion (pythonGH-98051)
  pythongh-97997: Add col_offset field to tokenizer and use that for AST nodes (python#98000)
  pythonGH-88968: Reject socket that is already used as a transport (python#98010)
  pythongh-96346: Use double caching for re._compile() (python#96347)
  pythongh-91708: Revert params note in urllib.parse.urlparse table (python#96699)
  pythongh-96265: Fix some formatting in faq/design.rst (python#96924)
  pythongh-73196: Add namespace/scope clarification for inheritance section (python#92840)
  pythongh-97646: Change `.js` and `.mjs` files mimetype to conform to RFC 9239 (python#97934)
  pythongh-97923: Always run Ubuntu SSL tests with others in CI (python#97940)
  pythongh-97956: Mention `generate_global_objects.py` in `AC How-To` (python#97957)
  pythongh-96959: Update HTTP links which are redirected to HTTPS (python#98039)
  ...
mpage pushed a commit to mpage/cpython that referenced this issue Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

0 participants