| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| color=self.color, | ||
| ) | ||
| else: | ||
| except TypeError: |
There was a problem hiding this comment.
TypeError seems a bit generic (you're calling user code).
What do you think about this?
len([v.kind for (k, v) in inspect.signature(self.formatter_class).parameters.items() if k in ('y', 'z') and v.kind in (inspect._ParameterKind.POSITIONAL_OR_KEYWORD, inspect._ParameterKind.KEYWORD_ONLY)]) == 2
Sorry, something went wrong.
There was a problem hiding this comment.
That doesn't work: FAILED (failures=2, errors=156)
Sorry, something went wrong.
There was a problem hiding this comment.
Wait, it does, obviously need to replace y and z :)
Sorry, something went wrong.
There was a problem hiding this comment.
I would not like to use inspect.signature() here. It is not reliable. If it fails (or return incorrect result), you cannot do anything with this. It can only be used in interactive introspection, when errors can be ignored.
Sorry, something went wrong.
|
Would you prefer the try/except or another approach? |
Sorry, something went wrong.
|
No, I think the user code should be changed. They use undocumented feature. |
Sorry, something went wrong.
|
We can do my original suggestion - make __init__ accept **kwargs and extract the new args with this. Already two external libraries were broken by this in the first alpha testing. Leaving this as it is will break user code for sure. |
Sorry, something went wrong.
|
This would not help. The problem is that the user code does not accept any arguments besides prog. And they do this because they use undocumented feature. |
Sorry, something went wrong.
|
What's the concern with inspect? That it won't work for some weird function? In that case we can just use the default values for these arguments. |
Sorry, something went wrong.
|
Another option is to set these fields through a setter method and not via __init__. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
The problem was with this code:
We want to set the extra arguments for HelpFormatter and argparse's own subclasses, which don't have their own __init__s.
But many third-party subclasses do have an __init__ and don't pass on kwargs. So we can't just check for a subclass of HelpFormatter, so let's try/except instead.