Skip to content

bpo-35178: Pass positional arguments to formatwarning(). #10343

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

Closed
wants to merge 1 commit into from

Conversation

tashrifbillah
Copy link
Contributor

@tashrifbillah tashrifbillah commented Nov 5, 2018

The last argument should be msg.line. Having line=msg.line generates an error message:
got an unexpected keyword arugument line=msg.line

Compare with Ln 99, the discrepancy should be apparent.

https://bugs.python.org/issue35178

The last argument should be `msg.line`. Having `line=msg.line` generates an error message:
`got an unexpected keyword arugument line=msg.line`
@the-knights-who-say-ni
Copy link

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

You can check yourself to see if the CLA has been received.

Thanks again for your contribution, we look forward to reviewing it!

@tashrifbillah
Copy link
Contributor Author

CLA has been signed separately

@serhiy-storchaka
Copy link
Member

Please open an issue on the bug tracker and describe how to reproduce the error.

@tashrifbillah
Copy link
Contributor Author

cc: @serhiy-storchaka

2018-11-06 09:51:27,314 /home/tb571/Downloads/pnlpipe/pnlscripts/wmql.py DEBUG  Running ['/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/scripts/tract_math', '/home/tb571/Downloads/pnlpipe/_data/003_GNX_007/Ukf-003_GNX_007-761f2a551e.vtk', 'tract_remove_short_tracts', '2', '/tmp/tmpq2z9fmfc/ukfpruned.vtk']
Traceback (most recent call last):
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/scripts/tract_math", line 115, in main
    tractography, *args.operation_parameters)
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tract_math/decorator.py", line 141, in wrapper
    process_output(out, file_output=file_output)
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tract_math/decorator.py", line 176, in process_output
    tractography_to_file(file_output, output)
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tractography/__init__.py", line 85, in tractography_to_file
    return tractography_to_vtk_file(filename, tractography, **kwargs)
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tractography/vtkInterface.py", line 29, in tractography_to_vtk_file
    tractography.tracts_data()
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tractography/vtkInterface.py", line 324, in write_vtkPolyData
    poly_data = tracts_to_vtkPolyData(tracts, tracts_data=tracts_data)
  File "/home/tb571/Downloads/pnlpipe/soft_dir/tract_querier-c57d670/tract_querier/tractography/vtkInterface.py", line 267, in tracts_to_vtkPolyData
    vtk_ids = ns.numpy_to_vtkIdTypeArray(ids, deep=True)
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/site-packages/vtk/util/numpy_support.py", line 198, in numpy_to_vtkIdTypeArray
    return numpy_to_vtk(num_array, deep, vtk.VTK_ID_TYPE)
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/site-packages/vtk/util/numpy_support.py", line 137, in numpy_to_vtk
    assert not numpy.issubdtype(z.dtype, complex), \
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/site-packages/numpy/core/numerictypes.py", line 743, in issubdtype
    FutureWarning, stacklevel=2
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/warnings.py", line 101, in _showwarnmsg
    _showwarnmsg_impl(msg)
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/warnings.py", line 28, in _showwarnmsg_impl
    text = _formatwarnmsg(msg)
  File "/home/tb571/miniconda3/envs/pnlpipe3/lib/python3.6/warnings.py", line 116, in _formatwarnmsg
    msg.filename, msg.lineno, line= msg.line)
TypeError: custom_formatwarning() got an unexpected keyword argument 'line'

@vstinner vstinner changed the title Typo/trivial mistake bpo-35178: Typo/trivial mistake Nov 6, 2018
@tashrifbillah
Copy link
Contributor Author

Hey @vstinner , any update on merge? Thanks!

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Please write a test checking that replacing warnings.formatwarning() with a new function, and the last parameter of this function is not called 'line', still works.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@serhiy-storchaka serhiy-storchaka changed the title bpo-35178: Typo/trivial mistake bpo-35178: Pass positional arguments to formatwarning(). Nov 9, 2018
@tashrifbillah
Copy link
Contributor Author

Hi guys,

Grammatically, there is nothing that prevents specifying the last argument with keyword line= . Based on this understanding, I found a monkey patching in the repo I was working on:

def custom_formatwarning(msg, *a):
    # ignore everything except the message
    return '\nWarning: ' + str(msg) + '\n'

warnings.formatwarning = custom_formatwarning

I believe the above patch was responsible for the error I got (can't see straight how though). I removed the monkey patch, and it's working fine now.

So, you are welcome to close the PR w/o merging.

@vstinner
Copy link
Member

https://bugs.python.org/issue35178 is a real bug and I like your fix, but a test must be written. Do you want to write a test? If not, I can ask someone else to do it.

@tashrifbillah
Copy link
Contributor Author

Hi @vstinner , based on my timing, I am unable to make a promise. So, please feel free to ask someone. Thanks!

@vstinner
Copy link
Member

vstinner commented Mar 7, 2019

Thanks @tashrifbillah! I merged PR #12033 written by @tirkarthi based on this PR.

@vstinner vstinner closed this Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants